Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] logging_json: fix RecursionError #453

Conversation

sebalix
Copy link
Member

@sebalix sebalix commented Jan 19, 2024

Since Python 3.10, the use of threading.currentThread() is deprecated and generates a warning, and generating this warning log was in turn entering in the logging_json mechanism, triggering an exception:

RecursionError: maximum recursion depth exceeded while calling a Python object

This error could be related to queue.job stuck in the state Started on some projects (to confirm).

EDIT: I confirm that this was blocking some jobs. I don't know why they weren't put in a Failed state but instead were still in Started, I didn't check.

Traceback:

[...]
  File "/odoo/external-src/odoo-cloud-platform/logging_json/json_log.py", line 29, in add_fields
    record.dbname = getattr(threading.currentThread(), "dbname", "?")
  File "/usr/local/lib/python3.10/threading.py", line 1449, in currentThread
    warnings.warn('currentThread() is deprecated, use current_thread() instead',
  File "/usr/local/lib/python3.10/warnings.py", line 109, in _showwarnmsg
    sw(msg.message, msg.category, msg.filename, msg.lineno,
  File "/odoo/src/odoo/netsvc.py", line 292, in showwarning_with_traceback
    return showwarning(
  File "/usr/local/lib/python3.10/logging/__init__.py", line 2245, in _showwarning
    logger.warning("%s", s)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1489, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1624, in _log
    self.handle(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1634, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1696, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 968, in handle
    self.emit(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/usr/local/lib/python3.10/site-packages/pythonjsonlogger/jsonlogger.py", line 133, in format
    self.add_fields(log_record, record, message_dict)
  File "/odoo/external-src/odoo-cloud-platform/logging_json/json_log.py", line 29, in add_fields
    record.dbname = getattr(threading.currentThread(), "dbname", "?")
  File "/usr/local/lib/python3.10/threading.py", line 1449, in currentThread
    warnings.warn('currentThread() is deprecated, use current_thread() instead',
  File "/usr/local/lib/python3.10/warnings.py", line 109, in _showwarnmsg
    sw(msg.message, msg.category, msg.filename, msg.lineno,
  File "/odoo/src/odoo/netsvc.py", line 292, in showwarning_with_traceback
    return showwarning(
  File "/usr/local/lib/python3.10/logging/__init__.py", line 2245, in _showwarning
    logger.warning("%s", s)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1489, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1624, in _log
    self.handle(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1634, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1696, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 968, in handle
    self.emit(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/usr/local/lib/python3.10/site-packages/pythonjsonlogger/jsonlogger.py", line 133, in format
    self.add_fields(log_record, record, message_dict)
  File "/odoo/external-src/odoo-cloud-platform/logging_json/json_log.py", line 29, in add_fields
    record.dbname = getattr(threading.currentThread(), "dbname", "?")
  File "/usr/local/lib/python3.10/threading.py", line 1449, in currentThread
    warnings.warn('currentThread() is deprecated, use current_thread() instead',
  File "/usr/local/lib/python3.10/warnings.py", line 109, in _showwarnmsg
    sw(msg.message, msg.category, msg.filename, msg.lineno,
  File "/odoo/src/odoo/netsvc.py", line 292, in showwarning_with_traceback
    return showwarning(
  File "/usr/local/lib/python3.10/logging/__init__.py", line 2245, in _showwarning
    logger.warning("%s", s)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1489, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1622, in _log
    record = self.makeRecord(self.name, level, fn, lno, msg, args,
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1591, in makeRecord
    rv = _logRecordFactory(name, level, fn, lno, msg, args, exc_info, func,
  File "/odoo/src/odoo/netsvc.py", line 135, in record_factory
    record = old_factory(*args, **kwargs)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 288, in __init__
    ct = time.time()

@sebalix sebalix changed the title logging_json: fix RecursionError [16.0][FIX] logging_json: fix RecursionError Jan 19, 2024
@sebalix sebalix added the bug label Jan 19, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 36.05%. Comparing base (99e6785) to head (f34dc6b).

Files Patch % Lines
logging_json/json_log.py 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             16.0     #453   +/-   ##
=======================================
  Coverage   36.05%   36.05%           
=======================================
  Files          33       33           
  Lines         760      760           
  Branches      106      106           
=======================================
  Hits          274      274           
  Misses        480      480           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cyrilmanuel cyrilmanuel force-pushed the 16-logging_json-fix-maximum_recursion_depth_exceeded branch 2 times, most recently from ab10688 to aa87497 Compare March 26, 2024 08:51
Since Python 3.10, the use of 'threading.currentThread()' is deprecated
and generates a warning, and generating this warning log was in turn
entering in the `logging_json` mechanism, triggering an exception:

RecursionError: maximum recursion depth exceeded while calling a Python object
@cyrilmanuel cyrilmanuel force-pushed the 16-logging_json-fix-maximum_recursion_depth_exceeded branch from aa87497 to f34dc6b Compare March 27, 2024 12:19
@cyrilmanuel cyrilmanuel merged commit 5b03cc4 into camptocamp:16.0 Mar 27, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants