Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12059 - Let TimeField.to_python correctly return a datetime.ti…

…me object when having a datetime object.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12137 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b7236b857626660b62800f66700dc887915b96af 1 parent 00252d8
@jezdez jezdez authored
View
2  django/db/models/fields/__init__.py
@@ -1036,7 +1036,7 @@ def to_python(self, value):
# 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
+ return value.time()
# Attempt to parse a datetime:
value = smart_str(value)
View
9 tests/regressiontests/datatypes/models.py
@@ -58,6 +58,15 @@ def __str__(self):
>>> d3.consumed_at
datetime.datetime(2007, 4, 20, 16, 19, 59)
+# Test for ticket #12059: TimeField wrongly handling datetime.datetime object.
+
+>>> d2.baked_time = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)
+>>> d2.save()
+
+>>> d3 = Donut.objects.all()[0]
+>>> d3.baked_time
+datetime.time(16, 19, 59)
+
# Year boundary tests (ticket #3689)
>>> d = Donut(name='Date Test 2007', baked_date=datetime.datetime(year=2007, month=12, day=31), consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59))
Please sign in to comment.
Something went wrong with that request. Please try again.