Opened 16 years ago

Closed 14 years ago

Last modified 13 years ago

#10970 closed (fixed)

auto_now_add for DateField evaluetes to datetime.datetime instance

Reported by: Ivan Gromov Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords: DateField, auto_now_add
Cc: summer.is.gone@…, cyberj@…, jjlorenzo@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've set auto_now_add to DateField, but it evaluates to datetime.datetime instance rather than datetime.date.
Here some example:

code in models.py

class Order(models.Model):
    created = models.DateField(auto_now_add=True)

and manage.py shell output:

In [1]: from app.models import Order
In [3]: o = Order()
In [4]: o.save()
In [5]: o.created
Out[5]: datetime.datetime(2009, 5, 1, 2, 53, 32, 280919)

I'm using django-1.0.2-final

Attachments (3)

auto_now_patch.diff (2.1 KB ) - added by Ivan Gromov 16 years ago.
auto_now_patch_1.diff (2.0 KB ) - added by Cyberj 15 years ago.
Patch for rev 12847
10970.diff (2.6 KB ) - added by Ramiro Morales 14 years ago.
Patch updated to r14002 (test fixed to actually fail before the fix and updated to unittest)

Download all attachments as: .zip

Change History (15)

comment:1 by Ivan Gromov, 16 years ago

Checked out to revision #10650, bug still there

comment:2 by Alex Gaynor, 16 years ago

Patch needs improvement: set

This patch doesn't work as DateTimeField relies on inhering this method.

comment:3 by Ramiro Morales, 16 years ago

Has patch: set
Needs tests: set

comment:4 by Tyson Clugg, 16 years ago

Surely datetime.date.today() is more concise than datetime.datetime.now().date() - is there a good reason why the latter was selected?

by Ivan Gromov, 16 years ago

Attachment: auto_now_patch.diff added

comment:5 by Ivan Gromov, 16 years ago

Nope, there wasn't reason to use datetime.now().date() instead datetime.date.today(). I've updated patch, thank you.

comment:6 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

by Cyberj, 15 years ago

Attachment: auto_now_patch_1.diff added

Patch for rev 12847

comment:7 by Cyberj, 15 years ago

Cc: cyberj@… added
Needs tests: unset
Patch needs improvement: unset

This bug remains an issue for applications like http://code.google.com/p/django-reversion/ because it takes a serialized datetime object for datefield with auto_now_add.

I've updated patch for r12846 and tests are OK

comment:8 by Ramiro Morales, 14 years ago

See #14037 for a manifestation of this bug when using Django's own serialization machinery)

comment:9 by José Jorge Lorenzo Vila, 14 years ago

Cc: jjlorenzo@… added

by Ramiro Morales, 14 years ago

Attachment: 10970.diff added

Patch updated to r14002 (test fixed to actually fail before the fix and updated to unittest)

comment:10 by Eric Holscher, 14 years ago

milestone: 1.3
Triage Stage: AcceptedReady for checkin

comment:11 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

(In [14029]) Fixed #10970 -- Initialize DateFields with datetime.date objects, not datetime.datetime. Thanks, summerisgone, Cyberj and Ramiro Morales.

comment:12 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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