-
Notifications
You must be signed in to change notification settings - Fork 485
Description
When starting the PictoPy backend using Python 3.12, the application crashes during startup with a RecursionError: maximum recursion depth exceeded. The error originates from the custom logging handler implementation, where the handler recursively logs messages using the same logging system it is attached to.
Environment
OS: Windows 11
Python: 3.12.7
Setup method: Official setup instructions followed
Steps to Reproduce
: Use Python 3.12.x (tested with Python 3.12.7)
: Clone the PictoPy repository
: Run the backend using python main.py
Expected Behavior
The backend server should start successfully and run without errors, initializing the API server and sync microservice as intended.
Actual Behavior
The backend crashes during startup with a RecursionError. The stack trace shows repeated calls inside the logging system until the maximum recursion depth is exceeded.
RecursionError: maximum recursion depth exceeded
File ".../logging/init.py", line XXXX, in emit
File ".../setup_logging.py", line 250, in emit
Root Cause Analysis
The issue is caused by a recursive logging loop in the custom logging handler defined in:
backend/app/logging/setup_logging.py
The emit() method of the custom handler performs the following logic:
It receives a log record
Calls get_logger(...)
Logs a new message using logger.log(...)
Because this logger is configured to use the same handler, calling logger.log() inside emit() re-enters the same handler, causing infinite recursion.
This behavior violates Python logging guidelines, which specify that logging handlers must not emit log messages using the same logging system they are handling.
The issue becomes visible on Python 3.12 due to stricter recursion and logging behavior. Earlier Python versions may not surface this problem as clearly.
Resolution Status
I have locally fixed this issue by modifying the custom logging handler to avoid emitting log records via the same logger inside emit(). After the fix:
The backend starts successfully
The API server initializes correctly
The sync microservice launches without errors
I am planning to open a pull request with the fix once maintainers confirm the preferred approach.