From e72f63dc548705cbdc58d2436fed187ac17717de Mon Sep 17 00:00:00 2001 From: debu-2 Date: Tue, 6 Oct 2026 07:20:02 +0530 Subject: [PATCH] human hand off fix --- backend/app/main.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 23d7e98..7362ae3 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -42,21 +42,22 @@ async def ensure_mongo_index(collection, keys, **options) -> None: desired_unique = bool(options.get("unique")) desired_sparse = bool(options.get("sparse")) - async for index in collection.list_indexes(): - if index["name"] == "_id_": - continue - index_key = list(index["key"].items()) - same_key = index_key == key_list - same_name = index["name"] == name - if not same_key and not same_name: - continue - same_options = ( - bool(index.get("unique")) == desired_unique - and bool(index.get("sparse")) == desired_sparse - ) - if same_key and same_name and same_options: - return - await collection.drop_index(index["name"]) + async with await collection.list_indexes() as cursor: + async for index in cursor: + if index["name"] == "_id_": + continue + index_key = list(index["key"].items()) + same_key = index_key == key_list + same_name = index["name"] == name + if not same_key and not same_name: + continue + same_options = ( + bool(index.get("unique")) == desired_unique + and bool(index.get("sparse")) == desired_sparse + ) + if same_key and same_name and same_options: + return + await collection.drop_index(index["name"]) await collection.create_index(keys, **options)