-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
added new variable that override pydantic fields definition with strawberry fields #3469
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -948,6 +948,27 @@ def age() -> int: | |
assert User.__strawberry_definition__.fields[2].base_resolver() == 84 | ||
|
||
|
||
def test_can_override_pydantic_with_strawberry_definition(): | ||
# Set variable override=False to pydantic type | ||
# That's override pydantic fields with strawberry fields | ||
class UserModel(BaseModel): | ||
new_name: Optional[str] = None | ||
new_age: Optional[int] = None | ||
|
||
@strawberry.experimental.pydantic.type(UserModel, override=False) | ||
class User: | ||
new_name: Optional[str] = None | ||
new_age: Optional[int] = strawberry.UNSET | ||
|
||
origin_user = UserModel() | ||
user = User() | ||
assert origin_user.new_name is None | ||
assert origin_user.new_age is None | ||
|
||
assert user.new_name is None | ||
assert user.new_age is strawberry.UNSET | ||
Comment on lines
+951
to
+969
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider adding a test case for when The current test only covers the scenario where
Comment on lines
+951
to
+969
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Add assertions to verify that the While the test checks the initial state of |
||
|
||
|
||
def test_can_convert_both_output_and_input_type(): | ||
class Work(BaseModel): | ||
time: float | ||
|
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 (code_clarification): Consider documenting the purpose and usage of the 'override' parameter.
Adding a new parameter with a default value is a significant change. It would be beneficial to include inline documentation or update the function's docstring to explain how this parameter affects the function's behavior.