#21738: models.F does not accept fields generated via QuerySet.extra
-------------------------------------+-------------------------------------
     Reporter:  tonnzor              |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:
     Keywords:                       |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by smeatonj):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 I think this ticket is somewhat related to
 https://code.djangoproject.com/ticket/14030

 Extra doesn't do anything smart. It stashes the raw value into a
 dictionary, and is simply added to the query on execution. Ideally, extra
 wouldn't be used at all. Instead, you should be able to:

 User.objects.annotate(new_is_active=SQL('CASE WHEN id > 100 THEN 1 ELSE 0
 END')).update(is_active=models.F('new_is_active'))

 I don't think there's any good reason to improve .extra() behaviour, as it
 is mostly a workaround for issues in other parts of the ORM which should
 be fixed instead.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21738#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 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/065.027d2dda47d3da465666472530bda8e4%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to