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

fix: Fix an issue preventing typing root with strawberry.Parent #3529

Merged
merged 2 commits into from
May 31, 2024

Conversation

bellini666
Copy link
Member

@bellini666 bellini666 self-assigned this May 31, 2024
@bellini666 bellini666 requested review from patrick91 and skilkis May 31, 2024 22:47
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @bellini666 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

strawberry/types/fields/resolver.py Show resolved Hide resolved
strawberry/types/fields/resolver.py Show resolved Hide resolved
strawberry/types/fields/resolver.py Show resolved Hide resolved
) and len(conflicting_arguments) > 1:
root_parameter is not None
and parent_parameter is not None
and root_parameter.name != parent_parameter.name
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Clarify the logic for checking parameter names.

The condition root_parameter.name != parent_parameter.name might benefit from a comment explaining why the names should not match. This will help future maintainers understand the rationale behind this check.

Suggested change
and root_parameter.name != parent_parameter.name
# Ensure the root and parent parameters do not refer to the same argument
and root_parameter.name != parent_parameter.name

@@ -453,3 +454,83 @@ def bar(x: str = "bar"):

assert len(parameters_map) == 2
assert len(parameters_set) == 2


def test_annotation_using_parent_annotation():
Copy link
Contributor

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 edge cases with null or invalid parent values.

To ensure robustness, it would be beneficial to add tests that handle cases where the parent parameter is None or an invalid type. This will help verify that the function behaves correctly under these conditions.

@botberry
Copy link
Member

botberry commented May 31, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release fixes a typing issue where trying to type a root argument with
strawberry.Parent would fail, like in the following example:

import strawberry


@strawberry.type
class SomeType:
    @strawberry.field
    def hello(self, root: strawberry.Parent[str]) -> str:
        return "world"

This should now work as intended.

Here's the tweet text:

🆕 Release (next) is out! Thanks to @_bellini666 for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link

codecov bot commented May 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.56%. Comparing base (6e790c1) to head (78595fe).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3529   +/-   ##
=======================================
  Coverage   96.55%   96.56%           
=======================================
  Files         523      523           
  Lines       33364    33404   +40     
  Branches     5522     5536   +14     
=======================================
+ Hits        32215    32255   +40     
  Misses        914      914           
  Partials      235      235           

Copy link

codspeed-hq bot commented May 31, 2024

CodSpeed Performance Report

Merging #3529 will not alter performance

Comparing fix_root_parent (78595fe) with main (6e790c1)

Summary

✅ 12 untouched benchmarks

@bellini666 bellini666 merged commit c78c30f into main May 31, 2024
66 checks passed
@bellini666 bellini666 deleted the fix_root_parent branch May 31, 2024 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can't use strawberry.Parent with root as it's name 😊
3 participants