Annotate list link attrs with Sequence type
This is beneficial as lists are invariant and we're using a union type here with User | Link[User], which means we can't assign a list[User] to the attr, which is very annoying.
This commit is contained in:
parent
8737897ce9
commit
8e82d7b661
|
@ -160,7 +160,9 @@ async def delete_category(category_id: PydanticObjectId, user: CurrentUserDep) -
|
|||
# and it's far more sensible solution than deleting all events with this category)
|
||||
events = await Event.find(category in Event.categories).to_list()
|
||||
for event in events:
|
||||
event.categories.remove(category)
|
||||
new_categories = list(event.categories)
|
||||
new_categories.remove(category)
|
||||
event.categories = new_categories
|
||||
await Event.replace_many(events)
|
||||
|
||||
# We can now safely delete the category
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from collections.abc import Sequence
|
||||
from datetime import UTC, date, datetime, time
|
||||
from typing import Annotated, ClassVar, final
|
||||
|
||||
|
@ -15,13 +16,13 @@ class Event(Document):
|
|||
user: Annotated[User, Annotated[Link[User], Indexed()]]
|
||||
title: str
|
||||
description: str
|
||||
categories: Annotated[list[Category | Link[Category]], Annotated[list[Link[Category]], Indexed()]]
|
||||
categories: Annotated[Sequence[Category | Link[Category]], Annotated[list[Link[Category]], Indexed()]]
|
||||
start_date: Annotated[date, Indexed()]
|
||||
start_time: time
|
||||
end_date: Annotated[date, Indexed()]
|
||||
end_time: time
|
||||
color: str # TODO: Consider using a complex rgb type
|
||||
attendees: Annotated[list[User | Link[User]], Annotated[list[Link[User]], Indexed()]]
|
||||
attendees: Annotated[Sequence[User | Link[User]], Annotated[list[Link[User]], Indexed()]]
|
||||
created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
|
||||
|
||||
@final
|
||||
|
|
Loading…
Reference in a new issue