Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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:

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

Download all attachments as: .zip

Change History (7)

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

my fix

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

updated patch

comment:1 Changed 6 years ago by ericholscher

  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by mtredinnick

  • 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 6 years ago by mtredinnick

  • Summary changed from to_python not being called on DateField/TimeField since they don't use Subfield metaclass to DateField/TimeField returning datetime objects (not date/time objects)

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

comment:4 Changed 6 years ago by ElliottM

  • Resolution set to invalid
  • Status changed from new to 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.

comment:5 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.