Do not raise AttributeError when parsing non-string UUIDs#1582
Merged
erikwrede merged 2 commits intographql-python:masterfrom Nov 9, 2024
Merged
Do not raise AttributeError when parsing non-string UUIDs#1582erikwrede merged 2 commits intographql-python:masterfrom
erikwrede merged 2 commits intographql-python:masterfrom
Conversation
0658a3e to
b9833cc
Compare
When a user sends a dictionary or other object as a UUID variable like `{[123]}`, previously graphene crashed with an `AttributeError`, like this:
```
(…)
File "…/lib/python3.12/site-packages/graphql/utils/is_valid_value.py", line 78, in is_valid_value
parse_result = type.parse_value(value)
^^^^^^^^^^^^^^^^^^^^^^^
File "…/lib/python3.12/site-packages/graphene/types/uuid.py", line 33, in parse_value
return _UUID(value)
^^^^^^^^^^^^
File "/usr/lib/python3.12/uuid.py", line 175, in __init__
hex = hex.replace('urn:', '').replace('uuid:', '')
^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'replace'
```
But an `AttributeError` makes it seem like this is the server's fault, when it's obviously the client's.
Report a proper GraphQLError.
b9833cc to
6cfc4c7
Compare
Member
|
Good catch! I adjusted your PR to keep allowing tuple-representations of UUIDs as well, and kept the error message consistent. Thanks for the Contribution 😊 |
erikwrede
approved these changes
Nov 9, 2024
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1582 +/- ##
==========================================
- Coverage 96.04% 96.00% -0.04%
==========================================
Files 51 51
Lines 1720 1728 +8
==========================================
+ Hits 1652 1659 +7
- Misses 68 69 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
erikwrede
approved these changes
Nov 9, 2024
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.
When a user sends a dictionary or other object as a UUID variable like
{[123]}, previously graphene crashed with anAttributeError, like this:But an
AttributeErrormakes it seem like this is the server's fault, when it's obviously the client's.Report a proper
GraphQLError.