-
Notifications
You must be signed in to change notification settings - Fork 123
JsonSchema can not be generated #601
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
Comments
The issue you are tripping over is that Redis OM Python hasn't been migrated over to pydantic v2 yet, we support it in that Redis OM Python and pydantic v2 can exist in the same project, but the validators for pydantic v2 will not work with Redis OM python (which is why you are seeing that error). See (__compat)[https://github.com/redis/redis-om-python/blob/main/aredis_om/_compat.py#L6] - basically if it sees you have pydantic v2 installed, it uses the v1 shim instead. FastAPI does somewhat the opposite (if you are on pydantic 1.x it more or less substitutes the fastAPI library with one compatible with pydantic 1.x) We will need to make sure we actually support v2, but that looks like it will be a fairly significant change, so at the moment you can support FastAPI 0.100.0+ by specifying a pre-v2 pydantic version: |
@slorello89 , thanks, but another question is, with the
How to get rid of additional |
pk is part of the RedisModel, It looks like it just doesn't have a proper value if you have a separate pk defined in your model |
@slorello89 I would like to use a custom field as primary key, as you see in my initial post. class ItemConfig(redis_om.HashModel):
"""
Item Config
"""
id: str = redis_om.Field(index=True, primary_key=True)
note: Optional[str]
purchase_price: Optional[float] Id field should - and also works as - primary key here. However, the model json definition still contains the Another solution could be to use the [...]
pk: str = redis_om.Field(index=True, primary_key=True, alias="id") However, here I get the error:
So what is the best way to use another name for the |
You can still specify that your |
Uh oh!
There was an error while loading. Please reload this page.
As I thought that the #597 resolves my issues, I found out that following still does not work (but worked with older pydantic/redis-om versions):
Dependencies:
Model definition:
FastAPI controller, using
ItemConfig
model as body parameter forPOST
endpoint:Navigating to the generated OpenAPI docs (
localhost:8080/docs
), getting error:It seems that the
redis-om
is not properly working with latestpydantic
versions, e.g. theItemConfig.model_json_schema
method is not defined (what is new way to get the json schema of a Model).@slorello89 @banker wdyt?
The text was updated successfully, but these errors were encountered: