#34699: Filtering on annotated TruncSecond expression gives unexpected result. -------------------------------------+------------------------------------- Reporter: Stefan | Owner: Wes P. Type: | Status: assigned Cleanup/optimization | Component: Database layer | Version: dev (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 1 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Comment (by Simon Charette):
Without a proper notion of typing / distinct types for Django naive vs aware datetime fields it is quite hard to make the experience better here. The way things are currently designed `DateTimeField` is expected to be naive if `USE_TZ = False` and aware otherwise, there's no way to represent naive `DateTimeField` at the ORM level when `USE_TZ = True`. Even on Postgres which has distinct types for naive and aware timestamps (`timestamp` and `timestamptz`) there's no warning emitted when mixing both; [https://dbfiddle.uk/xyLSKpNO it simply defaults to the globally configured timezone]. > Personally I feel the code should behave differently, but I don't see clearly how such fix would look or we would handle the potential deprecation/behavior change. Assuming we reach consensus that we want to make this behavior less of a footgun we could introduce a deprecation towards making `Trunc(tzinfo)` a required parameter when `USE_TZ = True; TIME_ZONE != "UTC"` to eventually make it default to `datetime.timezone.utc` when the deprecation period ends. -- Ticket URL: <https://code.djangoproject.com/ticket/34699#comment:17> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/django-updates/01070196119f759a-914bb34f-15d0-4cff-977f-3bb14a9b0f5e-000000%40eu-central-1.amazonses.com.