fix(query): Catch Django ValidationError for malformed query values#60
Merged
Conversation
Resolving a Model-typed `Query` field from its PK runs `Model.objects.filter(pk=value)`. A value the PK field cannot parse (e.g. a non-UUID string for a `UUIDField`) raises Django's `ValidationError`, which is not a subclass of `ValueError`, so `QueryPatcher`'s `except ValueError` let it escape: a stray `?param=garbage` in the URL raised during component build and returned an HTTP 500. Broaden both validation sites (`get_update_for_state` and `get_updates_for_params`) to also catch `ValidationError` and fall back to the field default. Add regression tests covering both methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolving a Model-typed
Queryfield from its PK runsModel.objects.filter(pk=value). A value the PK field cannot parse (e.g. a non-UUID string for aUUIDField) raises Django'sValidationError, which is not a subclass ofValueError, soQueryPatcher'sexcept ValueErrorlet it escape: a stray?param=garbagein the URL raised during component build and returned an HTTP 500.Broaden both validation sites (
get_update_for_stateandget_updates_for_params) to also catchValidationErrorand fall back to the field default. Add regression tests covering both methods.