#31639: F objects do not error when referencing transforms.
-------------------------------------+-------------------------------------
     Reporter:  Baptiste Mispelon    |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * stage:  Unreviewed => Accepted


Comment:

 I think the underlying issue here is that `F` objects simply don't support
 transforms but silently drops them when resolving to `Col`.

 For example, given the models you've provided

 {{{#!python
 Bill.objects.filter(issued_on__year=F('issued_on__year'))
 }}}

 Results in the following on SQLite

 {{{#!sql
 SELECT "db_functions_bill"."id", "db_functions_bill"."client_id",
 "db_functions_bill"."issued_on" FROM "db_functions_bill" WHERE
 django_date_extract('year', "db_functions_bill"."issued_on") =
 "db_functions_bill"."issued_on"
 }}}

 Notice how the right hand side of the filter `__year` transform doesn't
 result in wrapping what comes after the `=`.

 It's not an issue with `filter`'s compilation, `.annotate` exhibit the
 same behaviour

 {{{#!python
 Bill.objects.annotate(year=F('issued_on__year'))
 }}}

 {{{#!sql
 SELECT "db_functions_bill"."id", "db_functions_bill"."client_id",
 "db_functions_bill"."issued_on", "db_functions_bill"."issued_on" AS "year"
 FROM "db_functions_bill"
 }}}

 In the end, references to transforms via `F` is not supported and whether
 or not it should be discussed on the mailing list. Accepting the ticket on
 the basis that we should at least error out in this case.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31639#comment:1>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.6eb0d463b77a5fa22aab48a3759444b5%40djangoproject.com.

Reply via email to