Skip to content

Commit

Permalink
don't crash on empty post with fieldsets
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jun 13, 2023
1 parent 7898de4 commit 4eecf38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ def get_fields_for_config(self):
overrides = getattr(self.Meta, "wq_field_config", None) or {}

for name, field in list(fields.items()):

has_wq_config = False
if name != "id" and not field.read_only and not field.write_only:
has_wq_config = True
Expand Down Expand Up @@ -567,7 +566,7 @@ def to_virtual_fieldsets(self, data):
return data

def to_internal_value(self, data):
if not getattr(self.Meta, "wq_fieldsets", None):
if not data or not getattr(self.Meta, "wq_fieldsets", None):
return super().to_internal_value(data)

for name, conf in self.Meta.wq_fieldsets.items():
Expand Down
9 changes: 9 additions & 0 deletions tests/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,12 @@ def test_rest_virtual_fieldset(self):
self.assertEqual(
response.data, {"general": {"title": ["This field is required."]}}
)

def test_empty_post(self):
"""
Empty post should return 400, not 500
"""
response = self.client.post("/entities.json", data={})
self.assertTrue(
status.is_client_error(response.status_code), response.data
)

0 comments on commit 4eecf38

Please sign in to comment.