From e354759708497895a1503a2160c8233f45127409 Mon Sep 17 00:00:00 2001 From: Erik Wrede Date: Sat, 9 Nov 2024 18:38:36 +0100 Subject: [PATCH] fix: adjust exception message structure --- graphene/types/tests/test_uuid.py | 2 +- graphene/types/uuid.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/graphene/types/tests/test_uuid.py b/graphene/types/tests/test_uuid.py index c8f3947e..d031387b 100644 --- a/graphene/types/tests/test_uuid.py +++ b/graphene/types/tests/test_uuid.py @@ -47,7 +47,7 @@ def test_uuidstring_invalid_argument(): assert len(result.errors) == 1 assert ( result.errors[0].message - == "Variable '$uuid' got invalid value {'not': 'a string'}; UUID must be a string" + == "Variable '$uuid' got invalid value {'not': 'a string'}; UUID cannot represent value: {'not': 'a string'}" ) diff --git a/graphene/types/uuid.py b/graphene/types/uuid.py index 32f390d1..5f10a22e 100644 --- a/graphene/types/uuid.py +++ b/graphene/types/uuid.py @@ -29,6 +29,9 @@ def parse_literal(node, _variables=None): @staticmethod def parse_value(value): - if not isinstance(value, (str, _UUID)): - raise GraphQLError("UUID must be a string") - return _UUID(value) + if isinstance(value, _UUID): + return value + try: + return _UUID(value) + except (ValueError, AttributeError): + raise GraphQLError(f"UUID cannot represent value: {repr(value)}")