MCPcopy
hub / github.com/django/django / get_prep_lookup

Method get_prep_lookup

django/db/models/lookups.py:368–386  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

366 lookup_name = "exact"
367
368 def get_prep_lookup(self):
369 from django.db.models.sql.query import Query # avoid circular import
370
371 if isinstance(query := self.rhs, Query):
372 if not query.has_limit_one():
373 raise ValueError(
374 "The QuerySet value for an exact lookup must be limited to "
375 "one result using slicing."
376 )
377 lhs_len = len(self.lhs) if isinstance(self.lhs, (ColPairs, tuple)) else 1
378 if (rhs_len := query._subquery_fields_len) != lhs_len:
379 raise ValueError(
380 f"The QuerySet value for the exact lookup must have {lhs_len} "
381 f"selected fields (received {rhs_len})"
382 )
383 if not query.has_select_fields:
384 query.clear_select_clause()
385 query.add_fields(["pk"])
386 return super().get_prep_lookup()
387
388 def as_sql(self, compiler, connection):
389 # Avoid comparison against direct rhs if lhs is a boolean value. That

Callers

nothing calls this directly

Calls 4

has_limit_oneMethod · 0.80
clear_select_clauseMethod · 0.80
add_fieldsMethod · 0.45
get_prep_lookupMethod · 0.45

Tested by

no test coverage detected