#7801 closed (invalid)
DateField/TimeField returning datetime objects (not date/time objects)
Reported by: | 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)
Change History (7)
by , 16 years ago
Attachment: | date_time_metaclass.diff added |
---|
comment:1 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 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 , 16 years ago
Summary: | to_python not being called on DateField/TimeField since they don't use Subfield metaclass → DateField/TimeField returning datetime objects (not date/time objects) |
---|
Changed title to reflect the actual problem. The proposed solution is not correct.
comment:4 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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.
my fix