Skip to content

Conversation

@OlhaZahoruiko
Copy link
Contributor

Fixes maykinmedia/commonground-api-common#142

Changes

[Describe the changes here]

@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.92%. Comparing base (ff5f242) to head (178c973).

Files with missing lines Patch % Lines
src/objects/utils/views.py 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #723      +/-   ##
==========================================
- Coverage   84.98%   84.92%   -0.06%     
==========================================
  Files         141      141              
  Lines        2843     2832      -11     
  Branches      224      222       -2     
==========================================
- Hits         2416     2405      -11     
  Misses        375      375              
  Partials       52       52              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

🐰 Bencher Report

Branchfeature/142-custom-exception-handlers
Testbedubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_by_object_type📈 view plot
🚷 view threshold
125.32 ms
(+0.14%)Baseline: 125.13 ms
131.39 ms
(95.38%)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_one_result📈 view plot
🚷 view threshold
23.66 ms
(+1.14%)Baseline: 23.39 ms
24.56 ms
(96.32%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_1📈 view plot
🚷 view threshold
312.56 ms
(+1.30%)Baseline: 308.54 ms
323.97 ms
(96.48%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_5📈 view plot
🚷 view threshold
307.91 ms
(-0.35%)Baseline: 309.00 ms
324.45 ms
(94.90%)
performance_test/tests/test_objects_list.py::test_objects_api_list_small_page_size_page_20📈 view plot
🚷 view threshold
133.96 ms
(-0.18%)Baseline: 134.21 ms
140.92 ms
(95.06%)
🐰 View full continuous benchmarking report in Bencher

response = self.client.get(self.url, {"type": objecttype_url})

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, since the response is consistent with other projects, with invalid_params, etc., you can use this method to get the errors from vng_api_common.tests import get_validation_errors.

You can apply this for all tests as well.

Comment on lines 87 to 91
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}

self.assertEqual(
response.json()["type"],
[
f"Select a valid object type. {objecttype_url} is not one of the available choices."
],
invalid_params["type"],
f"Select a valid object type. {objecttype_url} is not one of the available choices.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}
self.assertEqual(
response.json()["type"],
[
f"Select a valid object type. {objecttype_url} is not one of the available choices."
],
invalid_params["type"],
f"Select a valid object type. {objecttype_url} is not one of the available choices.",
self.assertEqual(
get_validation_errors(response, "type"),
{
"name": "type",
"code": "invalid_choice",
"reason": f"Select a valid object type. {objecttype_url} is not one of the available choices.",
},
)

Copy link
Contributor

@danielmursa-dev danielmursa-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good 👍

zgw-consumers[setup-configuration]
mozilla-django-oidc-db[setup-configuration]
commonground-api-common[oas]
commonground-api-common[oas] @ git+https://github.com/maykinmedia/commonground-api-common.git@feature/142-exception-handler-mapping
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's upgrade this to 2.11.0

Suggested change
commonground-api-common[oas] @ git+https://github.com/maykinmedia/commonground-api-common.git@feature/142-exception-handler-mapping
commonground-api-common[oas]

@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch from 5ee4377 to 0dd574b Compare February 10, 2026 11:55
@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch 2 times, most recently from 6de9948 to d42b42e Compare February 10, 2026 14:21
Copy link
Collaborator

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remarks about tests, looks good otherwise

Comment on lines 200 to 207
def get_invalid_param(response, field):
data = response.json()

for param in data.get("invalid_params", []):
if param["name"] == field:
return param

raise AssertionError(f"No invalid_param found for field '{field}'")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can make use of from vng_api_common.tests import get_validation_errors for this I think

Suggested change
def get_invalid_param(response, field):
data = response.json()
for param in data.get("invalid_params", []):
if param["name"] == field:
return param
raise AssertionError(f"No invalid_param found for field '{field}'")

from sentry_sdk.transport import Transport

from ..views import exception_handler
from vng_api_common.exception_handling import exception_handler
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"status": 500,
"detail": "This search operation is not supported by the underlying data store.",
},
response.data["detail"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the assertion on the entire response dict, you can pop the UUID from the dict because that one varies per run

self.assertEqual(data["code"], "invalid")
self.assertIn("invalid_params", data)

ordering_error = next(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can also make use of get_validation_errors

self.assertEqual(data["code"], "invalid")
self.assertIn("invalid_params", data)

type_error = next(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can also make use of get_validation_errors

self.assertEqual(data["code"], "invalid")
self.assertIn("invalid_params", data)

type_error = next(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can also make use of get_validation_errors

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

🐰 Bencher Report

Branchfeature/142-custom-exception-handlers
Testbedubuntu-24.04
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_by_object_type📈 view plot
🚷 view threshold
120.71 ms
(-3.98%)Baseline: 125.72 ms
132.01 ms
(91.44%)
performance_test/tests/test_objects_list.py::test_objects_api_list_filter_one_result📈 view plot
🚷 view threshold
21.57 ms
(+1.51%)Baseline: 21.25 ms
22.31 ms
(96.68%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_1📈 view plot
🚷 view threshold
303.92 ms
(+0.80%)Baseline: 301.51 ms
316.58 ms
(96.00%)
performance_test/tests/test_objects_list.py::test_objects_api_list_large_page_size_page_5📈 view plot
🚷 view threshold
307.41 ms
(+2.12%)Baseline: 301.01 ms
316.06 ms
(97.26%)
performance_test/tests/test_objects_list.py::test_objects_api_list_small_page_size_page_20📈 view plot
🚷 view threshold
129.85 ms
(+0.50%)Baseline: 129.20 ms
135.66 ms
(95.71%)
🐰 View full continuous benchmarking report in Bencher


data = response.json()

invalid_params = {p["name"]: p for p in data["invalid_params"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invalid_params = {p["name"]: p for p in data["invalid_params"]}
error = get_validation_errors(response, "type")

self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

data = response.json()
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OlhaZahoruiko I think you can use this method everywhere to get the error dict

@stevenbal should we also add the key for validations that are not provided? like here

raise serializers.ValidationError(message, code=code)

Suggested change
invalid_params = {p["name"]: p["reason"] for p in data["invalid_params"]}
error = get_validation_errors(response, "")

@OlhaZahoruiko OlhaZahoruiko force-pushed the feature/142-custom-exception-handlers branch from f26f6b6 to 178c973 Compare February 12, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow defining a mapping of exceptions to responses for exception_handler

4 participants