| 4 | |
| 5 | The tests are failing because `RelatedIn` also needs adjustments to make sure it goes through `Query.set_values` instead of calling `clear_select_clause` and `add_fields` |
| 6 | |
| 7 | {{{#!diff |
| 8 | diff --git a/django/db/models/fields/related_lookups.py b/django/db/models/fields/related_lookups.py |
| 9 | index 1a845a1f7f..afea09b5a9 100644 |
| 10 | --- a/django/db/models/fields/related_lookups.py |
| 11 | +++ b/django/db/models/fields/related_lookups.py |
| 12 | @@ -93,7 +93,6 @@ def get_prep_lookup(self): |
| 13 | elif not getattr(self.rhs, "has_select_fields", True) and not getattr( |
| 14 | self.lhs.field.target_field, "primary_key", False |
| 15 | ): |
| 16 | - self.rhs.clear_select_clause() |
| 17 | if ( |
| 18 | getattr(self.lhs.output_field, "primary_key", False) |
| 19 | and self.lhs.output_field.model == self.rhs.model |
| 20 | @@ -105,7 +104,7 @@ def get_prep_lookup(self): |
| 21 | target_field = self.lhs.field.name |
| 22 | else: |
| 23 | target_field = self.lhs.field.target_field.name |
| 24 | - self.rhs.add_fields([target_field], True) |
| 25 | + self.rhs.set_values([target_field]) |
| 26 | return super().get_prep_lookup() |
| 27 | |
| 28 | def as_sql(self, compiler, connection): |
| 29 | }}} |