diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 25f44a4d1c7..4763940c81e 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1036,7 +1036,7 @@ class TimeField(Field): # 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) diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py index f6cbc9f0f64..0898b649b10 100644 --- a/tests/regressiontests/datatypes/models.py +++ b/tests/regressiontests/datatypes/models.py @@ -58,6 +58,15 @@ datetime.time(5, 30) >>> 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))