Opened 18 years ago

Closed 16 years ago

#3301 closed defect (fixed)

[multi-db] Bug in Fields.DateTimeField.pre_save()

Reported by: eric.helvey@… Owned by: nobody
Component: Database layer (models, ORM) Version: other branch
Severity: normal Keywords:
Cc: Triage Stage: Someday/Maybe
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

super call explicity names DateField instead of DateTimeField, thus bypassing the DateField.pre_save method that was intended. This causes DateTimeFields

Current:

def pre_save(self, model_instance, add):

value = super(DateField, self).pre_save(model_instance, add)
if value is not None:

# MySQL will throw a warning if microseconds are given, because it
# doesn't support microseconds.
settings = model_instance._default_manager.db.connection.settings
if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):

value = value.replace(microsecond=0)

return value

Fixed:

def pre_save(self, model_instance, add):

value = super(DateTimeField, self).pre_save(model_instance, add)
if value is not None:

# MySQL will throw a warning if microseconds are given, because it
# doesn't support microseconds.
settings = model_instance._default_manager.db.connection.settings
if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):

value = value.replace(microsecond=0)

return value

Attachments (1)

3301.diff (675 bytes ) - added by Gary Wilson <gary.wilson@…> 18 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by Eric Helvey <eric.helvey@…>, 18 years ago

I probably should have mentioned that this error was found in the http://code.djangoproject.com/svn/django/branches/multiple-db-support branch.

comment:2 by Gary Wilson <gary.wilson@…>, 18 years ago

Resolution: fixed
Status: newclosed
Summary: Bug in Fields.DateTimeField.pre_save()[multi-db] Bug in Fields.DateTimeField.pre_save()

noting in title that this is in multi-db branch

comment:3 by Gary Wilson <gary.wilson@…>, 18 years ago

Resolution: fixed
Status: closedreopened

oops, didn't mean to close it though

comment:4 by Gary Wilson <gary.wilson@…>, 18 years ago

FYI, this bug was introduced in [3394].

comment:5 by mir@…, 18 years ago

Triage Stage: UnreviewedAccepted
Version: SVNother branch

Note that I haven't tried to reproduce the bug, but the description is very good. Eric, if had made a nice patch out of your code description that basically describe the change to make, this would have been "Ready for Checkin".

by Gary Wilson <gary.wilson@…>, 18 years ago

Attachment: 3301.diff added

comment:6 by Gary Wilson <gary.wilson@…>, 18 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:7 by Jacob, 17 years ago

Triage Stage: Ready for checkinSomeday/Maybe

Since multi-db is (currently) unmaintained, I'm marking this someday/maybe.

comment:8 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: reopenedclosed

The multi-db is no longer active. Alternative approaches are being considered for trunk.

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