strawberry.pydantic.experimental.type strips all staticmethods from type definition besides from_pydantic()
and to_pydantic()
#3601
Labels
bug
Something isn't working
When a staticmethod not named
from_pydantic
orto_pydantic
is added to a type decorated withstrawberry.pydantic.experimental.type
it is not available at runtime. Attempting to call the staticmethod will result in an AttributeError.Describe the Bug
given an example type like this:
Running this code will result in `AttributeError: type object 'FooGQLType' has no attribute 'do_something'
In the pydantic type wrapper the
cls
object is redefined here usingdataclasses.make_dataclass()
:strawberry/strawberry/experimental/pydantic/object_type.py
Line 248 in cafc388
The
do_something
method is available as an attribute oncls
before this redefinition but is unavailable afterwards.Both
to_pydantic
andfrom_pydantic
are handled as special cases. If they exist on the type definition they are saved to the namespace dict before this redefinition and re-added after the fact. if they do not exist, the default definitions are suppliedSystem Information
Additional Context
I ran into this issue attempting to find a workaround for a question I posted in the discord titled "Conditionally override
from_pydantic()
"Upvote & Fund
The text was updated successfully, but these errors were encountered: