MariaDB slave setup is causing error while exporting csv with Report Builder

Hi,

Setup read operations from slave/secondary mysql system is enabled and everything working fine except: when I’m trying to export something, i.e: Sales Invoice list using the Report Builder feature, throwing this error.

Whereas, other default reports, i.e Sales Register, exporting them is working just fine. Can anyone please point out what went wrong?

Thanks in advance.

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 65, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1177, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 614, in wrapper_fn
    retval = fn(*args, **get_newargs(fn, kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/reportview.py", line 289, in export_query
    filters=form_params.filters)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/access_log/access_log.py", line 35, in make_access_log
    doc.insert(ignore_permissions=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 233, in insert
    self.set_new_name(set_name=set_name, set_child_names=set_child_names)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 423, in set_new_name
    set_new_name(self)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py", line 61, in set_new_name
    set_name_from_naming_options(autoname, doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py", line 96, in set_name_from_naming_options
    doc.name = _format_autoname(autoname, doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py", line 353, in _format_autoname
    name = re.sub(r"(\{[\w | #]+\})", get_param_value_for_match, autoname_value)
  File "/usr/local/lib/python3.7/re.py", line 194, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py", line 350, in get_param_value_for_match
    return parse_naming_series([trimmed_param], doc=doc)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py", line 170, in parse_naming_series
    part = getseries(n, digits)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py", line 200, in getseries
    current = frappe.db.sql("SELECT `current` FROM `tabSeries` WHERE `name`=%s FOR UPDATE", (key,))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 147, in sql
    self._cursor.execute(query, values)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 148, in execute
    result = self._query(query)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/cursors.py", line 310, in _query
    conn.query(q)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 775, in _read_query_result
    result.read()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1290, 'The MariaDB server is running with the --read-only option so it cannot execute this statement')

The error indicates that ERPNext couldn’t start a transaction within the slave.

How did you setup Master/Slave ? In the database level or app level (config) ?

The setup is a docker_swarm based setup following this frappe-docker-swarm

and then on the site_config.json setup this. Perhaps @revant_one could tell more about the mechanism of master-slave setup.

GitHub - bitnami/bitnami-docker-mariadb: Bitnami Docker Image for MariaDB this is where the replication setup is taken from

1 Like

Exporting a CSV file is triggering the creation of an Access Log. Since the db connected to the transaction is a read only one, the action fails.

This seems to be a bug in Frappe.

Edit: Raised a possible fix

https://github.com/frappe/frappe/pull/14142

3 Likes

@gavindsouza Hi,

The PR !14142 fixed the issue. Apparently I found a new one. Seems like it also causes issue while generating Trial Balance Report

@gavindsouza & @revant_one hi, could you test this new point that Trial balance report isn’t working?

@gavindsouza, hi, the issue with Trial Balance report generation, is it solved? can we create another issue on github?

image