Skip to content

datetime.utcnow() deprecation in Python 3.12 #2883

Closed

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

Activity

  1. SOORAJTS2001 commented on Nov 13, 2025

    @SOORAJTS2001

    Hi @neilsh, I just made a PR for it #2900

  2. bagerard commented on Aug 19, 2026

    @bagerard
    Collaborator

    updates were merged recently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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