Opened 16 years ago

Closed 16 years ago

Last modified 13 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: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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@…> 16 years ago.
my fix
datetime_date_time_field_fix_8156.diff (1.6 KB ) - added by Andrew Magee <amagee@…> 16 years ago.
updated patch

Download all attachments as: .zip

Change History (7)

by Andrew Magee <amagee@…>, 16 years ago

Attachment: date_time_metaclass.diff added

my fix

by Andrew Magee <amagee@…>, 16 years ago

updated patch

comment:1 by Eric Holscher, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:2 by Malcolm Tredinnick, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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 by ElliottM, 16 years ago

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 (http://code.google.com/p/django-mssql/ is the page for that project if you want to reporti there)

  • In django.db.backends.sqlite3.base.py and django.db.backends.mysql.base.py you can see django specifying to the sqlite3 module and the mysqldb module respectively which types to convert and how.

comment:5 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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