BeanieODM / beanie

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

Operator In not working #790

Open vargmurtter opened 8 months ago

vargmurtter commented 8 months ago

Discussed in https://github.com/roman-right/beanie/discussions/789

Originally posted by **vargmurtter** November 27, 2023 Hello everyone Maybe I do something wrong, but when I use In operator I got an error: ```bash File "/home/user/python/bots/play-bot/venv/lib64/python3.11/site-packages/beanie/odm/utils/relations.py", line 22, in convert_ids k_splitted = k.split(".") ^^^^^^^ AttributeError: 'PydanticObjectId' object has no attribute 'split' ``` My code: ```python class User(Document): tg_id: int username: str role: str name: str phone: str avatar_file_id: str language: str reg_date: datetime async def get_battles(self) -> list[TeamBattle]: return await TeamBattle.find( Or( In(self.id, TeamBattle.team_red), In(self.id, TeamBattle.team_blue) ) ).to_list() class TeamBattle(Document): owner_id: PydanticObjectId title: str description: str team_red: list[PydanticObjectId] team_blue: list[PydanticObjectId] creation_date: datetime end_date: datetime rating: int = 0 required_rating: int = 5 ``` What I do wrong?
Vwake04 commented 7 months ago

I think this might help

    async def get_battles(self) -> list[TeamBattle]:
        return await TeamBattle.find(
            Or(
                TeamBattle.team_red == self.id, 
                TeamBattle.team_blue == self.id
            )
        ).to_list()
roman-right commented 7 months ago

Hi, Thank you for the catch. I'll pick it up during the bug fixing session (this or next weekend).