-
Notifications
You must be signed in to change notification settings - Fork 35
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
Workaround for #150 FastAPI shows no attributes for models. #153
Conversation
geojson_pydantic/base.py
Outdated
@@ -53,7 +53,7 @@ def validate_bbox(cls, bbox: Optional[BBox]) -> Optional[BBox]: | |||
return bbox | |||
|
|||
@model_serializer(when_used="always", mode="wrap") | |||
def clean_model(self, serializer: Any, info: SerializationInfo) -> Dict[str, Any]: | |||
def clean_model(self, serializer: Any, info: SerializationInfo) -> Any: |
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.
@markus-work what happens if we use Dict
or Dict[Any, Any]
instead of Any
TBH, I'm not quite sure of all the implication of this change (cc @eseglem)
I would also add a comment in the code directly about this change/issue
I have been digging through this for a bit to get to the core of it, and it has something to do with how pydantic schema generation interacts with the Unfortunately, it does not look like I don't particularly like it, but the cleanest solution appears to be: def clean_model(self, serializer: Any, info: SerializationInfo): # type: ignore [no-untyped-def] Simple test, which could be parametrized for all the types: from geojson_pydantic import Point
def test_schema():
assert Point.model_json_schema(mode="validation") == Point.model_json_schema(
mode="serialization"
) I tried to work a solution with |
You're right, |
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.
Seems like the best solution for the time being. Think its worth adding any tests @vincentsarago ?
I added the test you suggested. I added the type hinting back locally to see if the test failed, and it did. So the test is valid for this problem. |
Should I update the changelog and run |
@markus-work I'll take care of the changelog 🙏 thank for the all the good work |
Just popping in here to say thank you! I just ran into this problem and ya'll just fixed it! <3 |
Thanks for chiming in @Kusmeroglu. It reminded me I still wanted to write up an issue on pydantic: pydantic/pydantic#8791 If anyone wants to thumbs up it, or chime in, could help with getting a nicer (less hacky) solution. |
What I am changing
How I did it
How you can test it
Related Issues