Skip to content

datetime.utcnow() deprecation in Python 3.12 #2883

@neilsh

Description

@neilsh

datetime.utcnow() was deprecated in Python 3.12, although it's referenced in quite a few places in MongoEngine's docs and test code, e.g.:

Note: To default the field to the current datetime, use: DateTimeField(default=datetime.utcnow)

It seems like it would make sense to do one of the following:

  • Update docs to e.g. DateTimeField(default=lambda: datetime.now(timezone.utc))
  • Create a timezone-aware helper called something like aware_utcnow, with behavior compatible across Python versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions