#34828: DateTimeField breaks when given datetime that would be invalid in UTC
-------------------------------------+-------------------------------------
     Reporter:  Denis Cornehl        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Denis Cornehl):

 Replying to [comment:3 David Sanders]:
 > > But shouldn't then the DateTimeField fail and not accept this
 datetime? Or is it expected behaviour like this?
 >
 > I don't think it's necessarily "expected" but it's a reasonable
 exception to be getting given the -1 year.  In this case `func()` is a
 psycopg2 (that's what I tested with) function – since Python's datetime
 min year is 1 then this is where errors will be thrown when it attempts to
 convert it to a Python type.
 >
 > I'm not sure what you mean by DateTimeField failing but fields don't
 validate data from the database 🤔 Is there something you had in mind?
 >

 I'm sorry, I could have elaborated in more detail.

 I see that when someone puts a timestamp into postgres that is outside of
 the range of a python datetime, we will see failures when retrieving this
 data.

 But seeing the example above, the invalid data is not bypassing anything
 but getting into the database via normal `DateTimeField` operations.

 Personally I would have expected that the model-field or at least the
 formfield would raise an exception when the user passes data that would
 lead to problems when trying to read it.
 In our case a user entered this value and then every request failed that
 tried to read this object in any way.

 ( of course my expectation might not fit what Django has in mind here,
 which is totally OK, then we would work around it)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34828#comment:4>
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/0107018a83fde6fa-cf69d1e8-0796-47fa-aee2-bddc37b48b54-000000%40eu-central-1.amazonses.com.

Reply via email to