summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-10 05:26:40 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-10 05:26:40 +0000
commitc545e88b817f299c7bb04c68a392cb5d52e7109b (patch)
tree433d3660374a63ec5c32c9419e0a48039adfeec4
parent9c770e05d448deeea6d0d9a27eb5a9f3805435c5 (diff)
[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
-rw-r--r--django/db/models/base.py2
-rw-r--r--django/db/models/fields/__init__.py5
-rw-r--r--tests/regressiontests/model_regress/models.py25
3 files changed, 30 insertions, 2 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index c02ca04b1e..62ebbab7f0 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -376,7 +376,7 @@ class Model(object):
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.")
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 7acb84bcc7..8da95bb4c4 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -813,6 +813,11 @@ class TimeField(Field):
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)
diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py
index 3c87e1c1e9..4bd27f2383 100644
--- a/tests/regressiontests/model_regress/models.py
+++ b/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 @@ datetime.datetime(2000, 1, 1, 6, 1, 1)
>>> 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
+
"""
-}
+