Report Builder data export fails with database readonly error


I am trying to get the data export feature from Report Builder to work.

I have created a filtered dataset within a DocType. However, when I choose Menu | Export I get the error:

Traceback (most recent call last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/", line 61, in application
    response = frappe.handler.handle()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/", line 24, in handle
    data = execute_cmd(cmd)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/", line 64, in execute_cmd
    return, **frappe.form_dict)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/", line 1064, in call
    return fn(*args, **newargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/", line 536, in wrapper_fn
    retval = fn(*args, **get_newargs(fn, kwargs))
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/desk/", line 157, in export_query
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/core/doctype/access_log/", line 35, in make_access_log
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 225, in insert
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 393, in set_new_name
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 42, in set_new_name
    set_name_from_naming_options(autoname, doc)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 75, in set_name_from_naming_options = _format_autoname(autoname, doc)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 298, in _format_autoname
    name = re.sub(r"(\{[\w | #]+\})", get_param_value_for_match, autoname_value)
  File "/home/erpnext/frappe-bench/env/lib/python3.6/", line 191, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 295, in get_param_value_for_match
    return parse_naming_series([trimmed_param], doc=doc)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 131, in parse_naming_series
    part = getseries(n, digits)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/", line 159, in getseries
    current = frappe.db.sql("SELECT `current` FROM `tabSeries` WHERE `name`=%s FOR UPDATE", (key,))
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/database/", line 156, in sql
    self._cursor.execute(query, values)
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 170, in execute
    result = self._query(query)
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 328, in _query
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 732, in _read_query_result
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 1075, in read
    first_packet = self.connection._read_packet()
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 684, in _read_packet
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 220, in check_error
  File "/home/erpnext/frappe-bench/env/lib/python3.6/site-packages/pymysql/", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.InternalError: (1290, 'The MariaDB server is running with the --read-only option so it cannot execute this statement')

I can see from the common_site_config.json on the ERPNext instance host that the value "read_from_replica": 1, is set, and when I check the status from within the replica database using SHOW GLOBAL VARIABLES LIKE 'read_only'; that read-only mode is ON

So my assumption is that ERPNext is set to read from the read-replica db, but the data export feature is blocked because the read replica is readonly.

I note that in my non-production environment which does not have replication on, the data export works fine.

My question then is how to get data export working in the production environment where ERPNext is confirgured to read from the read replica?

Or if there is a way to work around this?

Thank you.

Which version are you using? This should be fixed in all latest supported versions.


ERPNext: v12.14.0 (version-12)
Frappe Framework: v12.12.0 (version-12)