#36987: UUIDField.get_db_prep_value does not observe prepared argument
-------------------------------------+-------------------------------------
               Reporter:  Jacob      |          Owner:  Jacob Walls
  Walls                              |
                   Type:             |         Status:  assigned
  Cleanup/optimization               |
              Component:  Database   |        Version:  dev
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 The
 
[https://docs.djangoproject.com/en/6.0/ref/models/fields/#django.db.models.Field.get_db_prep_value
 doc'd "default" pattern] for fields is for `get_db_prep_value()` to call
 the `get_prep_value()` method if `prepared` is False. The idea being, I
 assume, to avoid wasted computation if the value is already
 `prepared=True`.

 `UUIDField` doesn't follow this pattern, causing two extra calls to
 `isinstance(val, UUID)` per value, which can add up for a large bag of
 values, e.g. a `prefetch_related()` call.

 Here is a [https://dryorm.xterm.info/uuidfield-get-db-prep-value fiddle]
 on DryORM with my fix branch checked out. Re-run the fiddle against main
 and notice 4 fewer calls to isinstance (2 * n objects).

 Discovered while reviewing the profile in a
 [https://github.com/django/django/pull/20779/changes micro-optimization
 PR]
 ----

 I acknowledge there is some exploratory effort toward removing this
 argument in a [https://github.com/django/django/pull/19051 draft PR].
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36987>
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 visit 
https://groups.google.com/d/msgid/django-updates/0107019cf6d815ea-24f07b66-7fad-45c0-98fb-ee63145db2aa-000000%40eu-central-1.amazonses.com.

Reply via email to