Make tz_aware=True the default?

133 views
Skip to first unread message

Charles Desbiens

unread,
Jun 24, 2022, 2:32:45 AM6/24/22
to MongoEngine Users
Hi,
I just want to gauge how people feel about the idea of changing the default value for the connect function's tz_aware kwarg to True.

The issue with the current value is that by default, if users follow the recommendation in the docs to save DateTimeFields using datetime.datetime.utcnow for the current time, the dates that they get back from the DB will always be off by whatever server's UTC offset is.

For example, if I save a document on a computer that's in the New York timezone and then immediately fetch that document, the date that I just made will be 4 hours in the future.

A lot of users don't even realize that you can pass tz_aware=True to the connect function. They follow the line that says "if you want to save the current time, use datetime.utcnow", and then they just get confused about why their dates are wrong.

I recently worked on a contract where people were pulling their hair out because of this. No one could find the exact source of the date drift. They had been dealing with issues like this for years.

I understand that this behavior is carried over from pymongo, but I feel that it's such a bad default that it's hard to justify carrying it over.

MongoDB doesn't have a concept of timezone unaware dates; everything is in UTC. Because of this, adding the option to have tz_aware=False doesn't make sense. It can only cause problems. It makes even less sense to have it as the default in my opinion.
Reply all
Reply to author
Forward
0 new messages