If datetimefield is not timezone-aware get_or_create fails. #1555
Unanswered
mmkhitaryan
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
SELECT "sold_date","id","review","created_at","seller_id","buyer_id","purshare_type_id" FROM "purchase" WHERE "id"=94562 AND "sold_date"='2024-02-10 13:55:04' AND "review"='' AND "purshare_type_id"=1 AND "buyer_id"=2 AND "seller_id"=1 LIMIT 2
This sql query got generated before I made the sold_date timezone.make_aware()
Before I made the datetime timezone-aware, get_or_none would fail with UNIQUE CONSTRAINT error.
I want to understand, is it a bug or a feature? Because to me it sounds like a bug. IMHO tortoise should at least show warning message that the datetime field must be timezone-aware.
Making the sold_date datetime field timezone-aware fixed the problem for me: mmkhitaryan/odinscraper@cfd1f70#diff-e544f072d0253f9a2c630fb985108e2f779a5d5db5e7eb0cb6319304756ceee3R107
I have implemented minimal reproducible example: https://gist.github.com/mmkhitaryan/bf46cb557cae421452ba938989005b70
When you run it, you get "successfully created" message but when the datetime is naive you get error below:
Beta Was this translation helpful? Give feedback.
All reactions