python Deprecation warning in Module logging_json, Python 3.11, Odoo 17
ahaly-compass opened this issue · 1 comments
Environment:
Odoo 17
Python: 3.11.7
OS: Debian Bookworm
python-json-logger==2.0.7
Error:
{"asctime": "2024-02-02 08:31:55,200", "pid": 1242, "levelname": "WARNING", "dbname": "odoo17-test", "name": "py.warnings", "message": "/data/odoo/3rd-party-addons/logging_json/json_log.py:29: DeprecationWarning: currentThread() is deprecated, use current_thread() instead\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/site-packages/gevent/baseserver.py", line 34, in _handle_and_close_when_done\n return handle(*args_tuple)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/site-packages/gevent/pywsgi.py", line 1577, in handle\n handler.handle()\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/site-packages/gevent/pywsgi.py", line 464, in handle\n result = self.handle_one_request()\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/site-packages/gevent/pywsgi.py", line 694, in handle_one_request\n self.handle_one_response()\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/site-packages/gevent/pywsgi.py", line 999, in handle_one_response\n self.run_application()\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/site-packages/gevent/pywsgi.py", line 945, in run_application\n self.result = self.application(self.environ, self.start_response)\n File "/data/odoo/odoo/odoo/http.py", line 2159, in call\n response = request._serve_db()\n File "/data/odoo/odoo/odoo/http.py", line 1713, in _serve_db\n self.registry = Registry(self.db).check_signaling()\n File "/data/odoo/odoo/odoo/modules/registry.py", line 89, in new\n return cls.new(db_name)\n File "", line 2, in new\n File "/data/odoo/odoo/odoo/tools/func.py", line 87, in locked\n return func(inst, *args, **kwargs)\n File "/data/odoo/odoo/odoo/modules/registry.py", line 113, in new\n odoo.modules.load_modules(registry, force_demo, status, update_module)\n File "/data/odoo/odoo/odoo/modules/loading.py", line 422, in load_modules\n loaded_modules, processed_modules = load_module_graph(\n File "/data/odoo/odoo/odoo/modules/loading.py", line 146, in load_module_graph\n _logger.info('loading %d modules...', module_count)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 1489, in info\n self._log(INFO, msg, args, **kwargs)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 1634, in _log\n self.handle(record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 1644, in handle\n self.callHandlers(record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 1706, in callHandlers\n hdlr.handle(record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 978, in handle\n self.emit(record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/handlers.py", line 526, in emit\n logging.FileHandler.emit(self, record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 1230, in emit\n StreamHandler.emit(self, record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 1110, in emit\n msg = self.format(record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/logging/init.py", line 953, in format\n return fmt.format(record)\n File "/opt/pyenv/versions/3.11.7/lib/python3.11/site-packages/pythonjsonlogger/jsonlogger.py", line 243, in format\n self.add_fields(log_record, record, message_dict)\n File "/data/odoo/3rd-party-addons/logging_json/json_log.py", line 29, in add_fields\n record.dbname = getattr(threading.currentThread(), "dbname", "?")\n", "perf_info": "", "request_id": "e52120b4-a36a-4af9-a650-d8fb7c6a782a", "uid": null}
Fix
replacing line 29 in json_log.py
record.dbname = getattr(threading.currentThread(), "dbname", "?")
with
record.dbname = getattr(threading.current_thread(), "dbname", "?")