It should be clarified that this occurs on the mysql backend, but not
the postgres backend. It has to do with how MySQL handles the DATETIME
object. You can't add a timedelta, because it expects a double.

I created a test app using a mysql backend and a Article model with
created and updated datetime fields.

created = 2010-10-15 09:13:02
updated = 2010-10-15 09:18:43

select created - updated from article_article
+-------------------+
| updated - created |
+-------------------+
|        541.000000 |
+-------------------+

It's using the YYYYMMDDHHMMSS format of the datetime fields:

20101015091843 - 20101015091302 = 541

The delta isn't constant either, here are two sets of times that are 5
minutes apart:

created=2010-10-15 09:00:00, updated=2010-10-15 09:05:00
mysql: select created - updated yiels 500

created=2010-10-15:09:59:00, updated=2010-10-15 10:04:00
mysql: select created - updated yields 4500

I haven't looked at the django mysql backend code, but based on this
that warning is fatal in your case because it's definitely not doing
what you want. And I don't see how you could write your query filter
in its current format so that it is postgres/mysql agnostic


On Fri, Oct 15, 2010 at 7:01 AM, Marc Aymerich <glicer...@gmail.com> wrote:
> This is a fork of this tread:
> http://groups.google.com/group/django-users/browse_thread/thread/5c6beb41fcf961a4
> I'm getting troubles combining instances of F() and timedelta. I'm working
> with the very last trunk revision (14232),
> I create a very simple model for troubleshoting the problem, the model is:
> class dates(models.Model):
>     date1 = models.DateField(auto_now_add=True)
>     date2 = models.DateField()
> And this is what I'm try to do:
>>>> from test.dates.dates import dates
>>>> from django.db.models import F
>>>> import datetime
>>>>
>>>> dates.objects.filter(date1__gte=F('date2')+datetime.timedelta(minutes=3))
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/usr/lib/python2.6/dist-packages/django/db/models/query.py", line
> 67, in __repr__
>     data = list(self[:REPR_OUTPUT_SIZE + 1])
>   File "/usr/lib/python2.6/dist-packages/django/db/models/query.py", line
> 82, in __len__
>     self._result_cache.extend(list(self._iter))
>   File "/usr/lib/python2.6/dist-packages/django/db/models/query.py", line
> 268, in iterator
>     for row in compiler.results_iter():
>   File "/usr/lib/python2.6/dist-packages/django/db/models/sql/compiler.py",
> line 675, in results_iter
>     for rows in self.execute_sql(MULTI):
>   File "/usr/lib/python2.6/dist-packages/django/db/models/sql/compiler.py",
> line 730, in execute_sql
>     cursor.execute(sql, params)
>   File "/usr/lib/python2.6/dist-packages/django/db/backends/util.py", line
> 18, in execute
>     return self.cursor.execute(sql, params)
>   File "/usr/lib/python2.6/dist-packages/django/db/backends/mysql/base.py",
> line 86, in execute
>     return self.cursor.execute(query, args)
>   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 168, in
> execute
>     if not self._defer_warnings: self._warning_check()
>   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 82, in
> _warning_check
>     warn(w[-1], self.Warning, 3)
> Warning: Truncated incorrect DOUBLE value: '0 0:3:0'
>
> On the parent
> thread http://groups.google.com/group/django-users/browse_thread/thread/5c6beb41fcf961a4 Alec
> reports that this works on their django installation.
> More over this pice of django code make use of
> it: http://code.djangoproject.com/attachment/ticket/10154/dateexpressions.diff
> Is this really a bug? it should be reported to django "bug tracker"?
> --
> Marc
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to