Skip to content

Commit 0cd57e2

Browse files
authored
Fix PK field lookup for Django < 5.2 (typeddjango#2860)
The `pk_fields` attribute was added in Django 5.2 to support composite primary keys. Fall back to using the `pk` attribute in earlier versions of Django. Regression in 736e30f.
1 parent 184304a commit 0cd57e2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mypy_django_plugin/transformers/querysets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,9 @@ def _validate_bulk_update_field(
784784
ctx.api.fail(f'"{method}()" can only be used with concrete fields. Got "{field_name}"', ctx.context)
785785
return False
786786

787-
all_pk_fields = set(opts.pk_fields)
787+
all_pk_fields = set(getattr(opts, "pk_fields", [opts.pk]))
788788
for parent in opts.all_parents:
789-
all_pk_fields.update(parent._meta.pk_fields)
789+
all_pk_fields.update(getattr(parent._meta, "pk_fields", [parent._meta.pk]))
790790

791791
if field in all_pk_fields:
792792
ctx.api.fail(f'"{method}()" cannot be used with primary key fields. Got "{field_name}"', ctx.context)

0 commit comments

Comments
 (0)