Fix using in operator with find method

This commit is contained in:
Peter Vacho 2024-12-25 21:24:38 +01:00
parent e66029ed36
commit cb5d6a63ee
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -2,6 +2,7 @@ from datetime import datetime
from typing import Annotated, final
from beanie import PydanticObjectId
from beanie.odm.operators.find.comparison import In
from fastapi import APIRouter, Body, HTTPException, Response, status
from pydantic import BaseModel, StringConstraints, field_validator
from pydantic_extra_types.color import Color
@ -158,7 +159,7 @@ async def delete_category(category_id: PydanticObjectId, user: CurrentUserDep) -
# First remove the association to this category by events
# (this may leave the event without a category, however that's fine, as event category is optional
# and it's far more sensible solution than deleting all events with this category)
events = await Event.find(category in Event.categories).to_list()
events = await Event.find(In(category, Event.categories)).to_list()
for event in events:
new_categories = list(event.categories)
new_categories.remove(category)