Opened 10 years ago

Closed 10 years ago

#3408 closed (worksforme)

DateField, TimeField, and DateTimeField to_python() handles null values incorrectly

Reported by: Brantley <deadwisdom@…> Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: master
Severity: Keywords: to_python, validation, model
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

DateField, TimeField, and DateTimeField all throw errors incorrectly during serialization and validation when they have a null value even if the model specifies that a null value is acceptable. The patch included simply checks for None as the value, then either returns that value, or raises an appropriate validation error if the field cannot be null.

Attachments (2)

__init__.py.diff (2.7 KB) - added by Brantley <deadwisdom@…> 10 years ago.
/django/db/models/fields/init.py
__init__.py.2.diff (1000 bytes) - added by Brantley <deadwisdom@…> 10 years ago.
/django/db/models/fields/__init.py__

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by Brantley <deadwisdom@…>

Attachment: __init__.py.diff added

/django/db/models/fields/init.py

Changed 10 years ago by Brantley <deadwisdom@…>

Attachment: __init__.py.2.diff added

/django/db/models/fields/__init.py__

comment:1 Changed 10 years ago by Brantley <deadwisdom@…>

Whoops, ignore the first file.

Also, come to think of it the TimeField doesn't even have a to_python. I'm not sure why so I didn't add it here.

comment:2 Changed 10 years ago by Chris Beaven

Triage Stage: UnreviewedReady for checkin

Makes sense

comment:3 Changed 10 years ago by Russell Keith-Magee

Resolution: worksforme
Status: newclosed

[4718] added fixes to null handling across the board; [4719] added unit-tests that validate this case specifically.

Note: See TracTickets for help on using tickets.
Back to Top