Skip to content

Fix/datetime utcnow deprecation#140

Open
Acuspeedster wants to merge 4 commits intofireform-core:mainfrom
Acuspeedster:fix/datetime-utcnow-deprecation
Open

Fix/datetime utcnow deprecation#140
Acuspeedster wants to merge 4 commits intofireform-core:mainfrom
Acuspeedster:fix/datetime-utcnow-deprecation

Conversation

@Acuspeedster
Copy link
Copy Markdown

Closes #139


Summary

Replaces deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc) in ORM models.


Problem

  • datetime.utcnow() deprecated in Python 3.12
  • Produces naive datetime objects
  • Can cause comparison errors
  • Not future-proof

Solution

  • Introduced private helper:
def _utcnow():
    return datetime.now(timezone.utc)
  • Used _utcnow as default_factory
  • Imported timezone from datetime

Using a named helper keeps default_factory serializable and explicit.

Impact

  • Fully timezone-aware timestamps
  • Forward-compatible with Python 3.12+
  • No schema migration required

…emplate tests with detailed assertions and mock setups
…utc)

datetime.utcnow() is deprecated since Python 3.12 and will be removed in
a future release. It returns a naive datetime with no timezone info, which
can cause silent bugs in comparisons. Replace both default_factory calls
in Template and FormSubmission with a private _utcnow() helper that
returns a timezone-aware UTC datetime via datetime.now(timezone.utc).
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.

[BUG]: datetime.utcnow() Deprecation

1 participant