#35434: prefetch_related_objects fails to cache UUID FKs when the string
representation of a UUID is used
-------------------------------------+-------------------------------------
     Reporter:  Selcuk Ayguney       |                    Owner:  (none)
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Documentation        |                  Version:  dev
     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
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

 * component:  Database layer (models, ORM) => Documentation
 * has_patch:  1 => 0
 * owner:  Selcuk Ayguney => (none)
 * stage:  Accepted => Unreviewed
 * status:  assigned => new
 * type:  Bug => Cleanup/optimization

Comment:

 Thanks, that helps me understand the severity of the anti-pattern.

 Now I'm aware that despite the implicit type-conversion you get on the
 database-side, python-side operations like `==` or `obj in queryset`
 become unsafe when a stringified UUID is assigned to a model attribute.

 Or even  `queryset.contains()`, but only if called on an evaluated
 queryset.


 {{{
 In [1]: from models import GraphModel

 In [2]: original = GraphModel.objects.first()

 In [3]: unsafe = GraphModel(str(original.pk))

 In [4]: all_graphs = GraphModel.objects.all()

 In [5]: all_graphs.contains(unsafe)
 Out[5]: True

 In [6]: len(all_graphs)
 Out[6]: 1

 In [7]: all_graphs.contains(unsafe)
 Out[7]: False

 }}}

 I think a version of that REPL would be useful in the docs somewhere.
 Calling your query tested by testing as far as line 5 but not line 7 is
 something I can see happening.

 Selcuk, is it okay if I reframe your ticket as a documentation request and
 ask for another opinion?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35434#comment:11>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f4afe98e9-93e3c21d-091f-458f-8877-1c0f2fc36662-000000%40eu-central-1.amazonses.com.

Reply via email to