-
-
Notifications
You must be signed in to change notification settings - Fork 146
Add support for strawberry.Maybe type in filter processing #805
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
base: main
Are you sure you want to change the base?
Add support for strawberry.Maybe type in filter processing #805
Conversation
- Updated resolve_value() to detect and handle Maybe instances - Extract .value attribute from Maybe with recursive resolution - Added comprehensive tests for Maybe support - Gracefully handles cases where Maybe is not available Closes strawberry-graphql#753
Reviewer's GuideExtend filter processing to support strawberry.Maybe types via recursive extraction in resolve_value and add corresponding test coverage ensuring compatibility across Strawberry versions. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Consider moving the import of
Maybeto module scope (or caching it) so you don’t re-try the import on every call to resolve_value. - You can simplify the
Maybehandling by always callingresolve_valueonvalue.value(sinceresolve_value(None)already returnsNone), removing the explicitif maybe_value is not Nonebranch.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider moving the import of `Maybe` to module scope (or caching it) so you don’t re-try the import on every call to resolve_value.
- You can simplify the `Maybe` handling by always calling `resolve_value` on `value.value` (since `resolve_value(None)` already returns `None`), removing the explicit `if maybe_value is not None` branch.
## Individual Comments
### Comment 1
<location> `tests/filters/test_filters_v2.py:160-165` </location>
<code_context>
+ maybe_with_value = Maybe(value="test_string")
+ assert resolve_value(maybe_with_value) == "test_string"
+
+ # Test Maybe with None
+ maybe_none = Maybe(value=None)
+ assert resolve_value(maybe_none) is None
+
+ # Test Maybe with nested types
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a test for Maybe with deeply nested None values.
Adding a test for Maybe(value=Maybe(value=None)) will help verify correct handling of nested None values.
```suggestion
# Test Maybe with nested types
maybe_enum = Maybe(value=Version.TWO)
assert resolve_value(maybe_enum) == Version.TWO.value
maybe_gid = Maybe(value=GlobalID("FruitNode", "42"))
assert resolve_value(maybe_gid) == "42"
# Test Maybe with deeply nested None value
maybe_deep_none = Maybe(value=Maybe(value=None))
assert resolve_value(maybe_deep_none) is None
```
</issue_to_address>
### Comment 2
<location> `tests/filters/test_filters_v2.py:177-179` </location>
<code_context>
+ maybe_gid = Maybe(value=GlobalID("FruitNode", "42"))
+ assert resolve_value(maybe_gid) == "42"
+
+ # Test Maybe in a list
+ maybe_list = [
+ Maybe(value=1),
+ Maybe(value="test"),
+ Maybe(value=None),
+ Maybe(value=Version.ONE),
+ ]
+ resolved_list = resolve_value(maybe_list)
+ assert resolved_list == [1, "test", None, Version.ONE.value]
+
+ # Test nested Maybe
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a test for lists containing nested Maybes.
Add a test with a list containing nested Maybe instances, such as [Maybe(value=Maybe(value="foo")), Maybe(value=None)], to verify resolve_value correctly handles nested Maybes.
```suggestion
# Test nested Maybe
nested_maybe = Maybe(value=Maybe(value="nested"))
assert resolve_value(nested_maybe) == "nested"
# Test list containing nested Maybes
nested_maybe_list = [
Maybe(value=Maybe(value="foo")),
Maybe(value=None),
]
resolved_nested_list = resolve_value(nested_maybe_list)
assert resolved_nested_list == ["foo", None]
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| # Test nested Maybe | ||
| nested_maybe = Maybe(value=Maybe(value="nested")) | ||
| assert resolve_value(nested_maybe) == "nested" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Consider adding a test for lists containing nested Maybes.
Add a test with a list containing nested Maybe instances, such as [Maybe(value=Maybe(value="foo")), Maybe(value=None)], to verify resolve_value correctly handles nested Maybes.
| # Test nested Maybe | |
| nested_maybe = Maybe(value=Maybe(value="nested")) | |
| assert resolve_value(nested_maybe) == "nested" | |
| # Test nested Maybe | |
| nested_maybe = Maybe(value=Maybe(value="nested")) | |
| assert resolve_value(nested_maybe) == "nested" | |
| # Test list containing nested Maybes | |
| nested_maybe_list = [ | |
| Maybe(value=Maybe(value="foo")), | |
| Maybe(value=None), | |
| ] | |
| resolved_nested_list = resolve_value(nested_maybe_list) | |
| assert resolved_nested_list == ["foo", None] |
- Updated resolve_value() to detect and handle Maybe instances - Moved Maybe import to module scope for better performance - Simplified Maybe handling by removing redundant None check - Extract .value attribute from Maybe with recursive resolution - Added comprehensive tests including nested Maybes and edge cases - Gracefully handles cases where Maybe is not available Closes strawberry-graphql#753
Description
This PR adds support for the
strawberry.Maybetype in the Django filter processing code, addressing issue #753.Changes
resolve_value()function instrawberry_django/filters.pyto detect and handlestrawberry.Maybeinstancestests/filters/test_filters_v2.pyTesting
Notes
strawberry.Maybeis not available in the installed versionCloses #753
Summary by Sourcery
Enable filter processing to recognize and unwrap strawberry.Maybe values by extracting and resolving their .value, with added test coverage for various Maybe scenarios.
New Features:
Enhancements:
Tests: