mssql-django 1.7.2 released — timezone fixes for DATETIMEOFFSET / Now(), and .explain() works again on Django 4.0+
We just shipped mssql-django 1.7.2, the Django backend for Microsoft SQL Server and Azure SQL. It's a small patch release but the timezone fixes are worth flagging if you use DATETIMEOFFSET columns or Now() with USE_TZ=True.
What's fixed:
DATETIMEOFFSETreturns timezone-aware datetimes. The backend was dropping the offset embedded in SQL Server's binaryDATETIMEOFFSETrepresentation, so values came back naive (or worse, silently reinterpreted). Now they come back with the righttzinfoattached. (#484, closes #371 and #136)Now()emitsSYSDATETIMEOFFSET()whenUSE_TZ=True**.** It was emittingSYSDATETIME(), which returns the SQL Server host's local time with no offset, so timestamps were silently shifted on non-UTC hosts.USE_TZ=Falsestill getsSYSDATETIME().QuerySet.explain()no longer raisesAttributeErroron Django 4.0+. Django 4.0 replacedquery.explain_format/query.explain_optionswithquery.explain_info; the compiler hadn't been updated. (#524, closes #409)- Removed a
returninside afinallyblock in a test utility that was swallowingBaseExceptionsubclasses, includingKeyboardInterrupt. (#526, closes #417)
If you previously worked around the DATETIMEOFFSET issue by manually attaching tzinfo to values, you'll want to review those workarounds — values from the ORM are now tz-aware by default.
Supported: Django 3.2 through 6.0, Python 3.8 through 3.14, SQL Server 2017 / 2019 / 2022 / 2025, Azure SQL DB / Managed Instance, ODBC Driver 17 or 18.
pip install --upgrade mssql-django
- Full blog post: https://techcommunity.microsoft.com/blog/sqlserver/announcing-mssql-django-1-7-2/4522336
- Release PR: https://github.com/microsoft/mssql-django/pull/528
- Repo / issues: https://github.com/microsoft/mssql-django