Opened 10 years ago

Closed 9 years ago

Last modified 6 years ago

#7801 closed (invalid)

DateField/TimeField returning datetime objects (not date/time objects)

Reported by: Andrew Magee <amagee@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:


I was having problems with TimeField's and DateField's returning datetime objects instead of date objects/time objects in sql server yesterday.
This is caused by the fact that DateField and TimeField don't use the SubfieldBase metaclass so their to_python methods are never called.
When i assign the metaclass everything works fine

Attachments (2)

date_time_metaclass.diff (1.0 KB) - added by Andrew Magee <amagee@…> 10 years ago.
my fix
datetime_date_time_field_fix_8156.diff (1.6 KB) - added by Andrew Magee <amagee@…> 10 years ago.
updated patch

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by Andrew Magee <amagee@…>

Attachment: date_time_metaclass.diff added

my fix

Changed 10 years ago by Andrew Magee <amagee@…>

updated patch

comment:1 Changed 10 years ago by Eric Holscher

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:2 Changed 10 years ago by Malcolm Tredinnick

Needs tests: set
Patch needs improvement: set

This looks a bit like symptom patching. No internal fields should need to use that metaclass. I'd prefer this to be fixed in a more direct fashion. Test cases that fail before the fix and work afterwards are also going to be needed here.

comment:3 Changed 10 years ago by Malcolm Tredinnick

Summary: to_python not being called on DateField/TimeField since they don't use Subfield metaclassDateField/TimeField returning datetime objects (not date/time objects)

Changed title to reflect the actual problem. The proposed solution is not correct.

comment:4 Changed 9 years ago by ElliottM

Resolution: invalid
Status: newclosed

All the type conversion things like this are handled by the database backend*. Since you're using an external backend, it would probably be better to fix it there rather than within django ( is the page for that project if you want to reporti there)

  • In and you can see django specifying to the sqlite3 module and the mysqldb module respectively which types to convert and how.

comment:5 Changed 6 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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