Opened 8 years ago

Closed 6 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@…> 8 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 8 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 8 years ago by Gary Wilson <gary.wilson@…>

  • Resolution set to fixed
  • Status changed from new to closed
  • Summary changed from Bug in Fields.DateTimeField.pre_save() to [multi-db] Bug in Fields.DateTimeField.pre_save()

noting in title that this is in multi-db branch

comment:3 Changed 8 years ago by Gary Wilson <gary.wilson@…>

  • Resolution fixed deleted
  • Status changed from closed to reopened

oops, didn't mean to close it though

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

FYI, this bug was introduced in [3394].

comment:5 Changed 8 years ago by mir@…

  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from SVN to other 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 8 years ago by Gary Wilson <gary.wilson@…>

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

  • Has patch set
  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 7 years ago by jacob

  • Triage Stage changed from Ready for checkin to Someday/Maybe

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

comment:8 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

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