I dont know why we cant open issues anymore on GitHub anyways:
Description of the issue
The Frappe Recorder is not compatible with read_from_replica=1
setups. When read_from_replica
is enabled, read queries are routed to the replica database connection (read_only_connection
), and these queries are not logged by the Recorder. This results in incomplete query logs, which affects debugging and performance monitoring.
Context information (for bug reports)
Output of bench version
+-----------------+---------+------------+---------+
| App | Version | Branch | Commit |
+-----------------+---------+------------+---------+
| erpnext | 15.49.3 | version-15 | de09da3 |
| frappe | 15.53.0 | version-15 | 3a636b1 |
| insights | 2.2.9 | main | fc81080 |
| wiki | 2.0.0 | master | 1366b5f |
+-----------------+---------+------------+---------+
Steps to reproduce the issue
- Enable
read_from_replica=1
insite_config.json
. - Perform database read operations that are routed to the replica database.
- Attempt to view the queries logged in the Recorder.
Observed result
- Queries routed to the replica database are not logged by the Recorder.
- An error may also occur if the Recorder attempts to unpatch SQL for the replica connection and
_sql
is not found.
Expected result
- The Recorder should log all queries, including those routed to the replica database.
- No errors should occur when unpatching SQL for the replica connection.
Stacktrace / full error message
AttributeError: 'MariaDBDatabase' object has no attribute '_sql'
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 114, in application
response = frappe.api.handle(request)
File "apps/frappe/frappe/api/__init__.py", line 49, in handle
data = endpoint(**arguments)
File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 50, in handle
data = execute_cmd(cmd)
File "apps/frappe/frappe/handler.py", line 86, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "apps/frappe/frappe/__init__.py", line 1726, in call
return fn(*args, **newargs)
File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
return func(*args, **kwargs)
File "apps/frappe/frappe/__init__.py", line 879, in wrapper_fn
retval = fn(*args, **get_newargs(fn, kwargs))
File "apps/frappe/frappe/desk/reportview.py", line 30, in get
data = compress(controller.get_list(args))
File "apps/frappe/frappe/core/doctype/recorder/recorder.py", line 57, in get_list
requests = Recorder.get_filtered_requests(args)[start : start + page_length]
File "apps/frappe/frappe/core/doctype/recorder/recorder.py", line 81, in get_filtered_requests
requests = [serialize_request(request) for request in get_recorder_data()]
File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
return func(*args, **kwargs)
File "apps/frappe/frappe/recorder.py", line 298, in wrapper
frappe.local._recorder.cleanup()
File "apps/frappe/frappe/recorder.py", line 244, in cleanup
self._unpatch_sql()
File "apps/frappe/frappe/recorder.py", line 291, in _unpatch_sql
frappe.db.sql = frappe.db._sql
AttributeError: 'MariaDBDatabase' object has no attribute '_sql'
Additional information
- OS version / distribution: (Distributor ID: Ubuntu / Description: Ubuntu 22.04.3 LTS / Release: 22.04 / Codename: jammy
- Frappe install method: (Same Issue In Docker And In Bench CLI)
- Database setup: Master-slave (replica) configuration with
read_from_replica=1
(MARIADB).