beanie
beanie copied to clipboard
Indexed not working with pydantic model
model
class LocationDD(BaseModel):
type: str = "Point"
coordinates: list[float, float]
class Drive(Document):
id_user: PydanticObjectId
ver: DriveType
location: Indexed(LocationDD, index_type=pymongo.GEOSPHERE)
body: str
is_completed: bool = False
route
@router.post("/create")
async def create_drive(drive: Drive):
print(drive)
await Drive.insert(drive)
return "Success"
The post request:
curl -X 'POST' \
'http://localhost:8000/drive/create' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"id_user": "5eb7cf5a86d9755df3a6c598",
"ver": "transporting_patient",
"location": {
"type": "Point",
"coordinates": [
16,16
]
},
"body": "string",
"is_completed": false
}'
prints:
id=None revision_id=None id_user=ObjectId('5eb7cf5a86d9755df3a6c597') ver=<DriveType.transporting_patient: 'transporting_patient'> location=LocationDD() body='string' is_completed=False
Seems like locationDD is not working properly.
When I am changing
location: Indexed(LocationDD, index_type=pymongo.GEOSPHERE)
To
location: Indexed(dict, index_type=pymongo.GEOSPHERE)
It works fine.
prints:
id=None revision_id=None id_user=ObjectId('5eb7cf5a86d9755df3a6c598') ver=<DriveType.transporting_patient: 'transporting_patient'> location={'type': 'Point', 'coordinates': [16, 16]} body='string' is_completed=False
note:
When I am not using Indexed
it works fine.
Hope someone can give me some idea what is happening.
Thank you for the issue. I'll pick this up soon. Looks like a Beanie-FastAPI incompatibility
This issue is stale because it has been open 30 days with no activity.
This issue was closed because it has been stalled for 14 days with no activity.