﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36987	UUIDField.get_db_prep_value does not observe prepared argument	Jacob Walls	Jacob Walls	"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 more 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]."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed		Aarni Koskela Tim Graham Simon Charette	Ready for checkin	1	0	0	0	0	0
