Closed johnson2427 closed 2 years ago
I think you forgot to run migrations first:
from fastapi import FastAPI
from redis_om import (
Migrator
)
app = FastAPI(title=__name__)
@app.on_event("startup")
async def startup():
await Migrator().run()
Update: Hey @johnson2427, i tried to run your code after running migrations, this time, i am getting the following error:
pydantic.error_wrappers.ValidationError: 1 validation error for Item
id
field required (type=value_error.missing
Removed the id field, and the endpoint works fine:
It seems like id
field is already defined in pydantic BaseModel, so try to rename it to something like id_
@wiseaidev Thank you! This let's me narrow it down, but renaming that id
field does not solve this issue. I still get pydantic.error_wrappers.ValidationError
Hey @johnson2427, just giving it a default
value seems to solve the issue:
id: int = Field(index=True, default=0)
I dunno how it works. MAGIC.
Update: I think there is a bug in the RedisModel
implementation for integer fields. Also, Item.find(Item.id == id).all()
won't work.
The only workaround, for now, is to rename the field to id_
of type str.
id_: str = Field(index=True)
In the meantime, I am trying to locate the bug.
Y'all would laugh so hard if i should you the bug:
It seems like the developer was trying to implement something, didn't like it, then forgot about removing the code. LOl
Time to run:
git blame aredis_om/model/model.py -L 1210,1213
0990c2e1 redis_developer/orm/model.py (Andrew Brookins 2021-09-15 17:41:45 -0700 1210) try:
d2fa4c58 redis_developer/model/model.py (Andrew Brookins 2021-10-20 13:01:46 -0700 1211) del fields["id"]
0990c2e1 redis_developer/orm/model.py (Andrew Brookins 2021-09-15 17:41:45 -0700 1212) except KeyError:
0990c2e1 redis_developer/orm/model.py (Andrew Brookins 2021-09-15 17:41:45 -0700 1213) pass
(END)
Ayo, Andrew!
hahahha, been there done that, no worries. I thought I was going insane. And I added the Migrator().run()
and it kept failing, so instead of adding too many things at once, Thank you for the help!
@simonprickett seems like this issues has had a bug fix already merged in and can be closed
What is the issue
I have created a FastAPI application, and I am trying to integrate aredis_om (but this fails with redis_om as well) with one of my rest endpoint modules.
I created a model called
Item
:As you can see in my endpoints file, I had to make a workaround to be able to pull the individual item, and to be able to get a list of items from Redis. My last endpoint, I believe is just wrong, I have to change id to a pk in order to get that item, so the last endpoint can be ignored.
My attempt for the first endpoint was this:
When I hit the endpoint with the .find() method I received a traceback of:
If you need more information from me, let me know! Thank you in advance.