Skip to content

chore: replace deprecated utcnow() with timezone-aware UTC timestamps#41

Merged
RichardAtCT merged 3 commits intoRichardAtCT:mainfrom
alexx-ftw:chore/utcnow-cleanup
Feb 19, 2026
Merged

chore: replace deprecated utcnow() with timezone-aware UTC timestamps#41
RichardAtCT merged 3 commits intoRichardAtCT:mainfrom
alexx-ftw:chore/utcnow-cleanup

Conversation

@alexx-ftw
Copy link
Copy Markdown
Contributor

Summary

This PR performs a repo-wide cleanup to replace deprecated datetime.utcnow() usage with timezone-aware UTC timestamps.

What changed

  • Replaced datetime.utcnow() with datetime.now(UTC) across touched source and tests.
  • Replaced default_factory=datetime.utcnow with default_factory=lambda: datetime.now(UTC) for dataclass fields.
  • Updated imports where needed to include UTC from datetime.

Scope

  • 16 files updated
  • No behavior changes intended beyond using timezone-aware UTC datetimes

Validation

  • Targeted suites:
    • poetry run pytest tests/unit/test_claude/test_session.py tests/unit/test_security/test_audit.py tests/unit/test_security/test_auth.py tests/unit/test_security/test_rate_limiter.py tests/unit/test_storage/test_repositories.py -q -r w
    • Result: 82 passed, 53 warnings
  • Near-full suite (excluding one known env-sensitive test):
    • poetry run pytest -q -r w -k "not sdk_manager_initialization_without_api_key"
    • Result: 270 passed, 1 deselected, 138 warnings

Notes on remaining warnings

Remaining warnings are not from utcnow() anymore:

  • aiosqlite/sqlite datetime adapter deprecation warnings in storage tests
  • one PytestCollectionWarning in tests/unit/test_events/test_bus.py

Known unrelated test failure in this environment

Running full suite without exclusion fails at:

  • tests/unit/test_claude/test_sdk_integration.py::TestClaudeSDKManager::test_sdk_manager_initialization_without_api_key

Reason: environment has ANTHROPIC_API_KEY set (value present), which conflicts with that test's expectation.

@alexx-ftw
Copy link
Copy Markdown
Contributor Author

Update: addressed the remaining warning sources in this branch.

Added in follow-up

  • Fixed PytestCollectionWarning in tests/unit/test_events/test_bus.py by renaming test event dataclass to BusTestEvent and updating references.
  • Added explicit sqlite adapters/converters in src/storage/database.py for TIMESTAMP, DATETIME, and DATE to avoid Python 3.12 default-adapter/default-converter deprecation warnings.
  • Updated storage model parsing (src/storage/models.py) to safely parse rows whether SQLite returns str or already-converted datetime objects.

Validation run

  • poetry run pytest tests/unit/test_storage/test_repositories.py tests/unit/test_storage/test_facade.py tests/unit/test_events/test_bus.py -q -r w → 28 passed, 0 warnings
  • poetry run pytest tests/unit/test_config.py tests/unit/test_security/test_validators.py tests/unit/test_claude/test_session.py -q -r w → 47 passed, 0 warnings
  • poetry run pytest -q -r w -k "not sdk_manager_initialization_without_api_key" → 270 passed, 1 deselected, 0 warnings

(That single deselected test remains environment-sensitive due to ANTHROPIC_API_KEY state in this runner.)

@alexx-ftw
Copy link
Copy Markdown
Contributor Author

Follow-up pushed to this PR ✅

I also applied the legacy session timestamp compatibility fix here:

  • src/claude/session.py
    • add _to_utc(dt)
    • normalize datetimes in is_expired, update_usage, and from_dict
  • tests/unit/test_claude/test_session.py
    • added tests for legacy naive timestamp normalization and expiry behavior

Validation:

  • poetry run pytest tests/unit/test_claude/test_session.py -q -r w
  • Result: 13 passed, 0 warnings

Commit: 308e1c7

Copy link
Copy Markdown
Owner

@RichardAtCT RichardAtCT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean maintenance PR. Tests pass (329 passed, 0 warnings), merges cleanly with main. Minor formatting issue in session.py (extra blank line) will be fixed post-merge.

@RichardAtCT RichardAtCT merged commit 0957760 into RichardAtCT:main Feb 19, 2026
1 check failed
RichardAtCT added a commit that referenced this pull request Feb 19, 2026
- Fix ProjectThreadModel.from_row() fromisoformat crash (datetime
  adapter from #41 returns datetime objects, not strings)
- Bulk autofix: unused imports, unused vars, trailing whitespace,
  line length, formatting (black + isort + autoflake)
- Add autoflake dev dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants