mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

datetime.utcnow() deprecation in Python 3.12

Open neilsh opened this issue 9 months ago • 1 comments

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

neilsh avatar Apr 24 '25 16:04 neilsh

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

SOORAJTS2001 avatar Nov 13 '25 02:11 SOORAJTS2001