Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify json error reporting #3286

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/grandchallenge/components/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def add_file_to_component_interface_value(
civ.full_clean()
except ValidationError as e:
civ.delete()
error = str(e)
error = str(e.message)
else:
user_upload.copy_object(to_field=civ.file)
civ.save()
Expand Down Expand Up @@ -1200,7 +1200,7 @@ def add_file_to_object(
civ = ComponentInterfaceValue.objects.get(pk=civ_pk)
object.values.remove(civ)
except ValidationError as e:
error = str(e)
error = str(e.message)

if error is not None:
Notification.send(
Expand All @@ -1209,7 +1209,7 @@ def add_file_to_object(
message=f"File for interface {interface.title} failed validation.",
target=object.base_object,
description=(
f"File for interface {interface.title} added to {object_pk} "
f"in {object.base_object.title} failed validation:\n{error}."
f"File for interface {interface.title} "
f"failed validation:\n{error}."
),
)
4 changes: 3 additions & 1 deletion app/grandchallenge/core/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def __call__(self, value):
try:
validate(value, self.schema, registry=self.registry)
except JSONValidationError as e:
raise ValidationError(f"JSON does not fulfill schema: {e}")
raise ValidationError(
f"JSON does not fulfill schema: instance {e.message.replace(str(e.instance) + ' ', '')}"
)

def __eq__(self, other):
return isinstance(other, JSONValidator) and self.schema == other.schema
Expand Down
2 changes: 1 addition & 1 deletion app/tests/components_tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_civ_post_value_required(kind):

# verify
assert not serializer.is_valid()
assert "JSON does not fulfill schema: None is not of type" in str(
assert "JSON does not fulfill schema: instance is not of type" in str(
serializer.errors["__all__"][0]
)

Expand Down