Opened 10 years ago

Closed 8 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: UI/UX:

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@…> 10 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 10 years ago by Eric Helvey <eric.helvey@…>

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 Changed 10 years ago by Gary Wilson <gary.wilson@…>

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 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Resolution: fixed
Status: closedreopened

oops, didn't mean to close it though

comment:4 Changed 10 years ago by Gary Wilson <gary.wilson@…>

FYI, this bug was introduced in [3394].

comment:5 Changed 10 years ago by mir@…

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".

Changed 10 years ago by Gary Wilson <gary.wilson@…>

Attachment: 3301.diff added

comment:6 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:7 Changed 9 years ago by Jacob

Triage Stage: Ready for checkinSomeday/Maybe

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

comment:8 Changed 8 years ago by Malcolm Tredinnick

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