beanie icon indicating copy to clipboard operation
beanie copied to clipboard

Indexed not working with pydantic model

Open ILmoshe opened this issue 2 years ago • 1 comments

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.

ILmoshe avatar Jun 07 '22 10:06 ILmoshe

Thank you for the issue. I'll pick this up soon. Looks like a Beanie-FastAPI incompatibility

roman-right avatar Jun 28 '22 15:06 roman-right

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Jan 08 '23 02:01 github-actions[bot]

This issue was closed because it has been stalled for 14 days with no activity.

github-actions[bot] avatar Jan 23 '23 02:01 github-actions[bot]