#24076: Query may fail with pytz exception -------------------------------------+------------------------------------- Reporter: lvella | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.6 (models, ORM) | Severity: Normal | Resolution: Keywords: | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by lvella): Replying to [comment:1 aaugustin]: > That's the intended behavior -- Django won't guess what you mean if you pass invalid inputs. But if using date to compare with datetime works 99% of the time, and there is no big warning in the documentation, saying that it must not be done, it clearly violates the principle of least astonishment. In such cases, either it should always work, or should always fail with an error. And it is not that hard to make it work, for instead of trying to add time information to the date before passing it to the database, the database type should be converted to date, dropping the time information in the process. Actually, my workaround in the case was to force Django to deliver my input in SQL as date, not as datetime: {{{ q = Ticket.objects.filter(register_time__gte=day + (F('id') - F('id'))) print(q.query) }}} yields: {{{ SELECT "reproduce_ticket"."id", "reproduce_ticket"."register_time" FROM "reproduce_ticket" WHERE "reproduce_ticket"."register_time" >= 2014-10-19 + ("reproduce_ticket"."id" - "reproduce_ticket"."id") }}} and it worked! Compare with the original query (with another date so it won't raise the exception): {{{ q = Ticket.objects.filter(register_time__gte=day) print(q.query) SELECT "reproduce_ticket"."id", "reproduce_ticket"."register_time" FROM "reproduce_ticket" WHERE "reproduce_ticket"."register_time" >= 2014-11-19 02:00:00 }}} -- Ticket URL: <https://code.djangoproject.com/ticket/24076#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.b4ad88b5620a66e1ec77833f479e605f%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.