Opened 18 years ago
Closed 16 years ago
#3301 closed defect (fixed)
[multi-db] Bug in Fields.DateTimeField.pre_save()
Reported by: | 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)
Change History (9)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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 , 18 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
oops, didn't mean to close it though
comment:5 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | SVN → 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".
by , 18 years ago
comment:6 by , 18 years ago
Has patch: | set |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:7 by , 17 years ago
Triage Stage: | Ready for checkin → Someday/Maybe |
---|
Since multi-db is (currently) unmaintained, I'm marking this someday/maybe.
comment:8 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
The multi-db is no longer active. Alternative approaches are being considered for trunk.
I probably should have mentioned that this error was found in the http://code.djangoproject.com/svn/django/branches/multiple-db-support branch.