Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.0.X] Fixed #10443 -- Fixed model attribute updating after r10004.

Adding a get_db_prep_save() call to the UpdateQuery code path meant it
was being called twice if you updated an existing model attribute. This
change removes that double call and also makes TimeField.to_python() a
little more robust for the benefit of the Oracle backend (just in case).

Backport of r10013 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10014 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c545e88b817f299c7bb04c68a392cb5d52e7109b 1 parent 9c770e0
@malcolmt malcolmt authored
View
2  django/db/models/base.py
@@ -376,7 +376,7 @@ def save_base(self, raw=False, cls=None, force_insert=False,
manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by())):
# It does already exist, so do an UPDATE.
if force_update or non_pks:
- values = [(f, None, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
+ values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
rows = manager.filter(pk=pk_val)._update(values)
if force_update and not rows:
raise DatabaseError("Forced update did not affect any rows.")
View
5 django/db/models/fields/__init__.py
@@ -813,6 +813,11 @@ def to_python(self, value):
return None
if isinstance(value, datetime.time):
return value
+ if isinstance(value, datetime.datetime):
+ # Not usually a good idea to pass in a datetime here (it loses
+ # information), but this can be a side-effect of interacting with a
+ # database backend (e.g. Oracle), so we'll be accommodating.
+ return value.time
# Attempt to parse a datetime:
value = smart_str(value)
View
25 tests/regressiontests/model_regress/models.py
@@ -1,5 +1,9 @@
# coding: utf-8
+import datetime
+
+from django.conf import settings
from django.db import models
+from django.utils import tzinfo
CHOICES = (
(1, 'first'),
@@ -140,5 +144,24 @@ def __unicode__(self):
>>> BrokenUnicodeMethod.objects.all()
[<BrokenUnicodeMethod: [Bad Unicode data]>]
+"""}
+
+if settings.DATABASE_ENGINE != "mysql":
+ __test__["non-mysql-tests"] = """
+# Saving an updating with timezone-aware datetime Python objects. Regression
+# test for #10443.
+
+# The idea is that all these creations and saving should work without crashing.
+# It's not rocket science.
+>>> Article.objects.all().delete()
+>>> dt1 = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(600))
+>>> dt2 = datetime.datetime(2008, 8, 31, 17, 20, tzinfo=tzinfo.FixedOffset(600))
+>>> obj = Article.objects.create(headline="A headline", pub_date=dt1, article_text="foo")
+
+>>> obj.pub_date = dt2
+>>> obj.save()
+>>> Article.objects.filter(headline="A headline").update(pub_date=dt1)
+1
+
"""
-}
+

0 comments on commit c545e88

Please sign in to comment.
Something went wrong with that request. Please try again.