#30224: Mysql Datetime value is string instead of datetime object
-------------------------------------+-------------------------------------
Reporter: Martin Kuhn | Owner: Rohit Jha
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Mysql | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Tobias Krönke):
Could we proceed with this issue with this very minimalistic failing
example?
== Failing with `AttributeError`
{{{
>>> SomeModel.objects.annotate(bla=Value(timezone.now(),
models.DateTimeField())).first().bla
AttributeError: 'str' object has no attribute 'utcoffset'
}}}
== Working with `Cast`
{{{
>>> SomeModel.objects.annotate(bla=Cast(Value(timezone.now(),
models.DateTimeField()), models.DateTimeField())).first().bla
datetime.datetime(2022, 6, 21, 8, 25, 39, 678166,
tzinfo=datetime.timezone.utc)
}}}
Are we asking everyone to always wrap all kinds of expressions involving
timestamps with `Cast`? There is no such hint in
https://docs.djangoproject.com/en/4.0/ref/models/expressions/#value-
expressions. We use `Value(<some datetime>)` a lot as fallbacks in `When`,
`Coalesce`, `Least`, ... expressions.
--
Ticket URL: <https://code.djangoproject.com/ticket/30224#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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070181856a19a2-f60886de-1695-4ec5-9d90-d6aea2f436dd-000000%40eu-central-1.amazonses.com.