(self)
| 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 |
nothing calls this directly
no test coverage detected