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

Return proper error instead of KeyError for invalid fragment type name #174

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

skovbasa
Copy link
Collaborator

@skovbasa skovbasa commented Nov 8, 2024

Right now if fragment references non-existing type hiku throws KeyError:

File "/usr/local/lib/python3.13/dist-packages/hiku/validate/query.py", line 527, in visit_fragment
    graph_node = self.graph.nodes_map[obj.type_name]

This PR fixes that behavior and returns proper validation errors in that case.
There are 2 real changes, rest is the black formatting. I marked changes in the comments to make review easier

@skovbasa skovbasa requested a review from kindermax November 8, 2024 01:03
@@ -523,6 +517,11 @@ def visit_fragment(self, obj: Fragment) -> t.Any:
self._type[-1].name is None and obj.type_name is None
):
graph_node = self.graph.root
elif obj.type_name not in self.graph.nodes_map:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

.

@@ -858,3 +955,19 @@ def test_any_in_option():
'Invalid value for option "root.get:foo", '
'"str" instead of Mapping[String, Any]'
]


def test_validate_query_fragment_on_unknown_type():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

.

@skovbasa skovbasa merged commit 0e0a921 into master Nov 8, 2024
7 checks passed
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.

2 participants