Opened 12 years ago
Closed 12 years ago
#19473 closed Uncategorized (invalid)
Getting a datetime.date object for a DateTimeField when using select_related with SQL Server
Reported by: | Mat Moore | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | select_related, datetime, datetimefield, sqlserver, db |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
When I use select_related, and the related model has a DateTimeField, I don't get a proper datetime.datetime when I then access that field. Instead I get a datetime.date.
If I set up the following models
from django.db import models class Author(models.Model): name = models.CharField(max_length=50) dob = models.DateTimeField() class Book(models.Model): author = models.ForeignKey(Author)
And then run the following:
from books.models import Author, Book import datetime author = Author(name='Bob', dob=datetime.datetime(1970, 1, 1, 0, 0, 0)) author.save() book = Book(author=author) book.save() print repr(Book.objects.filter(pk=book.pk)[0].author.dob) print repr(Book.objects.filter(pk=book.pk).select_related('author__dob')[0].author.dob)
I get the output
datetime.datetime(1970, 1, 1, 0, 0) datetime.date(1970, 1, 1)
I'm using MS SQL Server 2008 R2. I also tried running the above code with SQLLite, and in that case I get the datetime in both cases as expected.
Change History (2)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
MS SQL is not a database supported in Django core, so you should report a bug against the MS SQL adapter. If you can reproduce with one of the supported databases (SQLite, PostgreSQL, MySQL or Oracle), then reopen.