1. Michael Manfre
  2. django-mssql
  3. Issues


Issue #3 resolved

DateField returns datetime.datetime instead of datetime.date

Michael Manfre
repo owner created an issue

Issue 96 from google code https://code.google.com/p/django-mssql/issues/detail?id=96.

{{{ Reported by donato...@gmail.com, Oct 26, 2010

What steps will reproduce the problem? - create a model with a DateField: class Dates(models.Model): date = models.DateField()

  • save an instance with that field set, reload it and compare date field:

    from datetime import date today = date.today() d1 = Dates(date=today) d1.save() d1.date datetime.date(2010, 10, 26) d2 = Dates.objects.get(pk=d1.pk) d2.date datetime.datetime(2010, 10, 26, 0, 0) d1.date == d2.date False

What is the expected output? What do you see instead? d2.date should be an instance of 'date'. The same test run on MySQL gives correct results.

What version of Django, Python, Windows, SQL Server and django-msql are you using? Django: 1.2.3 Python: 2.6 Windows: XP SP3 Italian SQL Server: Express 2008 djang-mssql: latest to 2010-10-26

Please provide any additional information below.


Comment 1 by donato...@gmail.com, Oct 27, 2010

{{{ I roughly fixed the problem by changing compiler.SQLCompiler.resolve_columns method:

def resolve_columns(self, row, fields=()):
    # If the results are sliced, the resultset will have an initial 
    # "row number" column. Remove this column before the ORM sees it.
    if self._using_row_number:
        row = row[1:]

    if not fields:
        return row

    new_row = []
    for value, field in zip(row, fields):
        internal_type = field.get_internal_type()
        if internal_type == 'DateField':
    return new_row

Can it be a good choice?


Comments (2)

  1. Log in to comment