With CompositePrimaryKey, using OuterRef("pk")
in a subquery raises ValueError. Not certain if this is a release blocker or a new feature. If it's a new feature, we might want to document that it's not currently supported.
File "/Users/.../django/django/db/models/fields/tuple_lookups.py", line 32, in get_prep_lookup
self.check_rhs_is_tuple_or_list()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/.../django/django/db/models/fields/tuple_lookups.py", line 39, in check_rhs_is_tuple_or_list
raise ValueError(
f"{self.lookup_name!r} lookup of {lhs_str} must be a tuple or a list"
)
ValueError: 'exact' lookup of 'pk' must be a tuple or a list
Adjusting the guard that raises ValueError to also accept ResolvedOuterRef
leads to a more interesting failure:
File "/Users/.../django/django/db/models/expressions.py", line 1162, in as_sql
val = output_field.get_db_prep_value(val, connection=connection)
File "/Users/.../django/django/db/models/fields/related.py", line 1161, in get_db_prep_value
return self.target_field.get_db_prep_value(value, connection, prepared)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../django/django/db/models/fields/__init__.py", line 2819, in get_db_prep_value
value = self.get_prep_value(value)
File "/Users/.../django/django/db/models/fields/__init__.py", line 2129, in get_prep_value
raise e.__class__(
"Field '%s' expected a number but got %r." % (self.name, value),
) from e
TypeError: Field 'id' expected a number but got Col(composite_pk_comment, composite_pk.Comment.tenant).
Thank you Jacob
Marking as a release blocker. I think we might be able to resolve this but if not, agree we might want to document it within the not supported section.