We remove fields that shouldn't be seen on old versions of the API.
This was done with `pop(field name)`, which will throw an exception
if the named field is absent from the data. However, sometimes if
a patch request is via an old API version, we hit this line without
ever having the field present.

This is odd, but not harmful and we definitely shouldn't 500.

Fixes: d944f17ec059 ("REST: Use versioning for modified responses")
Signed-off-by: Daniel Axtens <d...@axtens.net>
---
 patchwork/api/base.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/patchwork/api/base.py b/patchwork/api/base.py
index 89a43114f9e7..6cb703b12bbb 100644
--- a/patchwork/api/base.py
+++ b/patchwork/api/base.py
@@ -96,6 +96,9 @@ class 
BaseHyperlinkedModelSerializer(HyperlinkedModelSerializer):
             # field was added, we drop it
             if not utils.has_version(request, version):
                 for field in self.Meta.versioned_fields[version]:
-                    data.pop(field)
+                    # After a PATCH with an older API version, we may not see
+                    # these fields. If they don't exist, don't panic, return
+                    # (and then discard) None.
+                    data.pop(field, None)
 
         return data
-- 
2.30.2

_______________________________________________
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to