mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-15 08:24:55 +00:00
Normalize to strings to handle form encoded data
This commit is contained in:
@@ -714,15 +714,18 @@ class BatchedManyRelatedField(serializers.ManyRelatedField):
|
||||
pks.append(item)
|
||||
|
||||
try:
|
||||
found = {obj.pk: obj for obj in child.get_queryset().filter(pk__in=pks)}
|
||||
# str() normalizes int vs string PKs — form data sends strings, JSON sends ints
|
||||
found = {
|
||||
str(obj.pk): obj for obj in child.get_queryset().filter(pk__in=pks)
|
||||
}
|
||||
except (TypeError, ValueError):
|
||||
child.fail("incorrect_type", data_type=type(pks[0]).__name__)
|
||||
|
||||
result = []
|
||||
for pk in pks:
|
||||
if pk not in found:
|
||||
if str(pk) not in found:
|
||||
child.fail("does_not_exist", pk_value=pk)
|
||||
result.append(found[pk])
|
||||
result.append(found[str(pk)])
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user