Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Malcolm Tredinnick authored March 10, 2009
2  django/db/models/base.py
@@ -376,7 +376,7 @@ def save_base(self, raw=False, cls=None, force_insert=False,
376 376
                     manager.filter(pk=pk_val).extra(select={'a': 1}).values('a').order_by())):
377 377
                 # It does already exist, so do an UPDATE.
378 378
                 if force_update or non_pks:
379  
-                    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]
  379
+                    values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
380 380
                     rows = manager.filter(pk=pk_val)._update(values)
381 381
                     if force_update and not rows:
382 382
                         raise DatabaseError("Forced update did not affect any rows.")
5  django/db/models/fields/__init__.py
@@ -813,6 +813,11 @@ def to_python(self, value):
813 813
             return None
814 814
         if isinstance(value, datetime.time):
815 815
             return value
  816
+        if isinstance(value, datetime.datetime):
  817
+            # Not usually a good idea to pass in a datetime here (it loses
  818
+            # information), but this can be a side-effect of interacting with a
  819
+            # database backend (e.g. Oracle), so we'll be accommodating.
  820
+            return value.time
816 821
 
817 822
         # Attempt to parse a datetime:
818 823
         value = smart_str(value)
25  tests/regressiontests/model_regress/models.py
... ...
@@ -1,5 +1,9 @@
1 1
 # coding: utf-8
  2
+import datetime
  3
+
  4
+from django.conf import settings
2 5
 from django.db import models
  6
+from django.utils import tzinfo
3 7
 
4 8
 CHOICES = (
5 9
     (1, 'first'),
@@ -140,5 +144,24 @@ def __unicode__(self):
140 144
 >>> BrokenUnicodeMethod.objects.all()
141 145
 [<BrokenUnicodeMethod: [Bad Unicode data]>]
142 146
 
  147
+"""}
  148
+
  149
+if settings.DATABASE_ENGINE != "mysql":
  150
+    __test__["non-mysql-tests"] = """
  151
+# Saving an updating with timezone-aware datetime Python objects. Regression
  152
+# test for #10443.
  153
+
  154
+# The idea is that all these creations and saving should work without crashing.
  155
+# It's not rocket science.
  156
+>>> Article.objects.all().delete()
  157
+>>> dt1 = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(600))
  158
+>>> dt2 = datetime.datetime(2008, 8, 31, 17, 20, tzinfo=tzinfo.FixedOffset(600))
  159
+>>> obj = Article.objects.create(headline="A headline", pub_date=dt1, article_text="foo")
  160
+
  161
+>>> obj.pub_date = dt2
  162
+>>> obj.save()
  163
+>>> Article.objects.filter(headline="A headline").update(pub_date=dt1)
  164
+1
  165
+
143 166
 """
144  
-}
  167
+

0 notes on commit c545e88

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