Code

Ticket #12059: 12059.diff

File 12059.diff, 1.4 KB (added by simonz05, 4 years ago)
Line 
1Index: django/db/models/fields/__init__.py
2===================================================================
3--- django/db/models/fields/__init__.py (revision 11743)
4+++ django/db/models/fields/__init__.py (working copy)
5@@ -835,7 +835,7 @@
6             # Not usually a good idea to pass in a datetime here (it loses
7             # information), but this can be a side-effect of interacting with a
8             # database backend (e.g. Oracle), so we'll be accommodating.
9-            return value.time
10+            return value.time()
11 
12         # Attempt to parse a datetime:
13         value = smart_str(value)
14Index: tests/regressiontests/datatypes/models.py
15===================================================================
16--- tests/regressiontests/datatypes/models.py   (revision 11743)
17+++ tests/regressiontests/datatypes/models.py   (working copy)
18@@ -58,6 +58,15 @@
19 >>> d3.consumed_at
20 datetime.datetime(2007, 4, 20, 16, 19, 59)
21 
22+# Test for ticket #12059: TimeField wrongly handling datetime.datetime object.
23+
24+>>> d2.baked_time = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)
25+>>> d2.save()
26+
27+>>> d3 = Donut.objects.all()[0]
28+>>> d3.baked_time
29+datetime.time(16, 19, 59)
30+
31 # Year boundary tests (ticket #3689)
32 
33 >>> 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))