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

Validation error with Json pydantic field #131

Closed
unidesigner opened this issue Jan 4, 2022 · 4 comments
Closed

Validation error with Json pydantic field #131

unidesigner opened this issue Jan 4, 2022 · 4 comments

Comments

@unidesigner
Copy link

I use a JSONB column in Postgres, but I do get an error on the GET all route with my specified pydantic model with json_field: Optional[pydantic.Json] = None with proper json data in my database table. The exception is:

..../python3.9/site-packages/fastapi/routing.py", line 137, in serialize_response
    raise ValidationError(errors, field.type_)
pydantic.error_wrappers.ValidationError: 2 validation errors for MyModel
response -> 0
  value is not a valid dict (type=type_error.dict)

Any idea how to fix that? Thanks.

@unidesigner
Copy link
Author

This may be a related issue in pydantic-sqlalchemy

@awtkns
Copy link
Owner

awtkns commented Jan 5, 2022

Hi @unidesigner, my first thought is that this may be a pydantic-sqlalchemy issue as you mentioned. Would you be able to provide a more complete code example of how it is being used?

@unidesigner
Copy link
Author

Hi @awtkns, thanks for getting back to me. Yes, you are right, it is likely a pydantic-sqlalchemy issue and I should go and check there. I will report back once I solve the issue.

@unidesigner
Copy link
Author

I don't know if it was an issue with my code, but I could get the Json field to work with SQLModel. I don't see that (async) SQLModel is yet supported but it would not be too difficult to add I guess, and I saw there is already a related issue #109 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants