BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
2.04k stars 215 forks source link

[BUG] Document model with nullable indexed field cannot be initialized after v1.21 #713

Closed IterableTrucks closed 11 months ago

IterableTrucks commented 1 year ago

Describe the bug From v1.21.0, init_beanie no longer supports initializing models with nullable indexed field. Instead it raises AttributeError: _indexed in the init_indexes method

To Reproduce

import asyncio
from datetime import datetime
from typing import Optional

from beanie import Document, init_beanie, Indexed

class UserProfile(Document):
    name: str
    last_login: Optional[Indexed(datetime)]

async def main():
    await init_beanie(connection_string="mongodb://localhost:27017/test", document_models=[UserProfile])

asyncio.run(main())

Expected behavior The code snippet runs without exception and creates an index on last_login in v1.20.0 and older versions

Additional context AttributeError was raised in v1.21.0 & v1.22.x
Pydantic version is 1.10.12 After upgrading pydantic to 2.3.0, the code runs without exception but it does not create index on last_login field,

roman-right commented 1 year ago

Hi! Thank you for the catch. I'll check and fix it this/next week.

IterableTrucks commented 11 months ago

v1.23.2 has fixed this bug.