-
-
Notifications
You must be signed in to change notification settings - Fork 91
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: no blank children names #666
base: main
Are you sure you want to change the base?
Conversation
wrote this when attempting to debug this issue
while trying to understand the codebase
This reverts commit 075a4ed. Causing issues with old py
field_name="", | ||
# this is a fake field name, but it makes it possible to debug which type variant | ||
# is the source of an exception downstream | ||
field_name=f"{field_name}__{arg.__name__}", |
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.
is there a reason we couldn't
- just use
field_name
- specify
arg.__name__
as a separate field on field_meta
current approach here feels bad
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.
Currently, I believe the main use is mapping this back to the model itself. For subfields, guessing currently unused so field_name
could work and feels preferable to above.
What is the issue with having no field name? Is this to improve exception message based on test? If that is the case then maybe could update on that side instead
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.
What is the issue with having no field name?
I ran into this when attempting to run a FactoryModel.build()
command. The ParameterException
said that a factory for a type was missing, but it the name was blank, so I couldn't determine which field was causing the error.
For subfields, guessing currently unused so
field_name
could work and feels preferable to above
Great, I'll change the PR to just use field_name
instead.
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 ran into this when attempting to run a FactoryModel.build() command. The ParameterException said that a factory for a type was missing, but it the name was blank, so I couldn't determine which field was causing the error.
Where is that error coming from? Does the type matter there?
Probably clearer to have field_name
regardless
@@ -106,7 +106,7 @@ def is_new_type(annotation: Any) -> "TypeGuard[type[NewType]]": | |||
|
|||
|
|||
def is_annotated(annotation: Any) -> bool: | |||
"""Determine whether a given annotation is 'typing.Annotated'. | |||
"""Determine whether a given annotation is 'typing.Annotated', or a similar typing annotation such as Optional. |
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.
Is this correct? The function looks for annotated origin or similar
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.
this is why i left this comment, it's pretty tricky
In [12]: a
Out[12]: typing.Optional[int]
In [13]: a.__args__
Out[13]: (int, NoneType)
In [14]: b = int | None
Out[14]: int | None
In [15]: b.__args__
Out[15]: (int, NoneType)
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.
Does this match _AnnotatedAlias
or other conditions?
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'm not familiar with _AnnotatedAlias
, not sure...
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.
Based on testing in terminal think this handles this correctly so fine as is?
>>> from polyfactory.utils.predicates import is_annotated
>>> from typing import Optional
>>> is_annotated(Optional[int])
False
>>> is_annotated(int | None)
False
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.
Overall looks good. Can you review failing tests?
class OptionalFormTwo(BaseModel): | ||
optional_custom_type_second_form: CustomType | None | ||
|
||
@classmethod |
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.
Is this needed? This is not used by the factory
Description
ensure no blank field names on children variants