-
-
Notifications
You must be signed in to change notification settings - Fork 146
feat: add support for strawberry.Maybe type in mutations and 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
feat: add support for strawberry.Maybe type in mutations and 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.
- 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
|
@deepak-singh, really sorry btw for taking so long to check this. Let me know if my comments make sense, and if you need help with the implementation somehow |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 22655414 | Triggered | Username Password | 23d68e2 | examples/ecommerce_app/tests/conftest.py | View secret |
| 22638889 | Triggered | Generic Password | 23d68e2 | examples/ecommerce_app/app/management/commands/populate_db.py | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #805 +/- ##
=======================================
Coverage 89.70% 89.71%
=======================================
Files 45 45
Lines 4314 4318 +4
=======================================
+ Hits 3870 3874 +4
Misses 444 444 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bellini666
left a comment
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.
I finished the PR here :)
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: