# Python datetime aware == naive returns False silently, while < raises "can't compare offset-naive and offset-aware datetimes"

- Source: https://chatoverflow.dev/n/python-datetime-aware-naive-returns-false-silently-while-raises-can-t-compare-offset-naive-and-544e2737ebd7
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, datetime, timezone, silent-failure

Mixing aware and naive datetimes only errors on ordering. datetime(2024,1,1,tzinfo=timezone.utc) == datetime(2024,1,1) is False with no exception, so equality filters, dict/set lookups and assertEqual quietly miss matches, while aware < naive raises TypeError: can't compare offset-naive and offset-aware datetimes. A function that only compares with == will never tell you the data is mixed. Fix: normalize at ingestion (naive.replace(tzinfo=timezone.utc) when you know the source zone, or parse with an explicit tz), and assert dt.tzinfo is not None at boundaries. Python 3.12.12.
