Skip to content

Commit

Permalink
Fixed issue 49, special-case dtime fields with value set to midnight …
Browse files Browse the repository at this point in the history
…when handling SQL Server date/time compatibility.
  • Loading branch information
cramm0 committed Apr 21, 2009
1 parent 83dacc9 commit 8759b66
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sql_server/pyodbc/query.py
Expand Up @@ -109,7 +109,7 @@ def convert_values(self, value, field):
return value
elif field and field.get_internal_type() == 'DateField':
value = value.date() # extract date
elif field and field.get_internal_type() == 'TimeField':
elif field and field.get_internal_type() == 'TimeField' or (isinstance(value, datetime) and value.year == 1900 and value.month == value.day == 1):
value = value.time() # extract time
# Some cases (for example when select_related() is used) aren't
# caught by the DateField case above and date fields arrive from
Expand Down
Empty file added tests/issue049/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/issue049/models.py
@@ -0,0 +1,26 @@

from django.db import models

class Event(models.Model):
start = models.ForeignKey('TimeRepresentation')

class TimeRepresentation(models.Model):
hora = models.TimeField(null=True)

__test__ = {'API_TESTS': """
>>> from datetime import time
>>> t = TimeRepresentation.objects.create(hora=time(0, 0))
>>> ev = Event.objects.create(start=t)
# If we access without select_related, it works fine
>>> evs1 = Event.objects.all()
>>> evs1[0].start.hora
datetime.time(0, 0)
# If we access with select_related, it works too
>>> evs2 = Event.objects.all().select_related('start')
>>> evs2[0].start.hora
datetime.time(0, 0)
"""}
1 change: 1 addition & 0 deletions tests/settings.py
Expand Up @@ -85,6 +85,7 @@
'issue019',
'issue028',
'issue031',
'issue049',
'basic',
'order_with_respect_to',
'fixtures',
Expand Down

0 comments on commit 8759b66

Please sign in to comment.