Skip to content

[MNT] Deprecation of datetime.utcnow() and improvement of synchronization logic #737

@MOHITKOURAV01

Description

@MOHITKOURAV01

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:

  1. Datetime Modernization: Replace all instances of utcnow() and utcfromtimestamp() with timezone-aware datetime.now(UTC) in:
    • aiod_entry.py
    • bookmark.py
    • Routers and Connectors.
  2. Standardized Logging: Update error_handling.py to use logging.exception() for better traceability.
  3. Synchronization Refactoring: Use the csv module in synchronization.py to make error reporting more robust and remove redundant logic.
  4. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions