3.16.0 UniqeTogetherConstraint checker causes server error

106 views
Skip to first unread message

Marco Glauser

unread,
Apr 7, 2025, 6:36:24 AMApr 7
to Django REST framework
We recently upgraded to 3.16.0.
We started getting errors on this line:
https://github.com/encode/django-rest-framework/blob/c41314f1fc898490f27e1015cc859e28afe6f7b9/rest_framework/validators.py#L191C1-L191C87

Added with this PR:
https://github.com/encode/django-rest-framework/pull/9360


After some debugging we managed to narrow down that the error happens during a PATCH api call. We're only patching one field and get a KeyError on a field that is neither the patched one or  unique.

As a starting example, where a+b are unique together:
{
  "a": 1,
  "b": 2,
  "c": 3
}

When we Patch
{
  "a": 5
}

We get the exception:
File "/usr/local/lib/python3.13/site-packages/rest_framework/validators.py", line 191, in __call__
condition_kwargs = {source: attrs[source] for source in self.condition_fields}
                                ~~~~~^^^^^^^^
KeyError: 'c'


Downgrading to 3.15.2, no exception is raised.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages