Describe the bug / Optimization
Currently, the codebase uses datetime.utcnow() and datetime.utcfromtimestamp() in several core modules. As of Python 3.12, these methods are officially deprecated and can lead to bugs because they return "naive" datetime objects (without timezone info).
Additionally, the current error handling and synchronization logic in synchronization.py and error_handling.py use legacy methods like traceback.print_exc(), which are less effective for production logging.
Proposed Changes
I propose a modernization of the time handling and logging logic:
- Datetime Modernization: Replace all instances of
utcnow() and utcfromtimestamp() with timezone-aware datetime.now(UTC) in:
aiod_entry.py
bookmark.py
- Routers and Connectors.
- Standardized Logging: Update
error_handling.py to use logging.exception() for better traceability.
- Synchronization Refactoring: Use the
csv module in synchronization.py to make error reporting more robust and remove redundant logic.
- Test Updates: Update
test_bookmark_endpoints.py to ensure compatibility with timezone-aware objects.
Expected impact
- Future-proof code that is compatible with Python 3.12+.
- More reliable timestamp comparisons in tests and production.
- Better error visibility in logs.
Additional context
I have already verified these changes locally, and all 30 relevant tests in src/tests/ are passing. I am ready to submit a PR for this!
Describe the bug / Optimization
Currently, the codebase uses
datetime.utcnow()anddatetime.utcfromtimestamp()in several core modules. As of Python 3.12, these methods are officially deprecated and can lead to bugs because they return "naive" datetime objects (without timezone info).Additionally, the current error handling and synchronization logic in
synchronization.pyanderror_handling.pyuse legacy methods liketraceback.print_exc(), which are less effective for production logging.Proposed Changes
I propose a modernization of the time handling and logging logic:
utcnow()andutcfromtimestamp()with timezone-awaredatetime.now(UTC)in:aiod_entry.pybookmark.pyerror_handling.pyto uselogging.exception()for better traceability.csvmodule insynchronization.pyto make error reporting more robust and remove redundant logic.test_bookmark_endpoints.pyto ensure compatibility with timezone-aware objects.Expected impact
Additional context
I have already verified these changes locally, and all 30 relevant tests in
src/tests/are passing. I am ready to submit a PR for this!