human hand off fix

This commit is contained in:
debu-2 2026-10-06 07:20:02 +05:30
parent 7b39f956e6
commit e72f63dc54

View file

@ -42,21 +42,22 @@ async def ensure_mongo_index(collection, keys, **options) -> None:
desired_unique = bool(options.get("unique")) desired_unique = bool(options.get("unique"))
desired_sparse = bool(options.get("sparse")) desired_sparse = bool(options.get("sparse"))
async for index in collection.list_indexes(): async with await collection.list_indexes() as cursor:
if index["name"] == "_id_": async for index in cursor:
continue if index["name"] == "_id_":
index_key = list(index["key"].items()) continue
same_key = index_key == key_list index_key = list(index["key"].items())
same_name = index["name"] == name same_key = index_key == key_list
if not same_key and not same_name: same_name = index["name"] == name
continue if not same_key and not same_name:
same_options = ( continue
bool(index.get("unique")) == desired_unique same_options = (
and bool(index.get("sparse")) == desired_sparse bool(index.get("unique")) == desired_unique
) and bool(index.get("sparse")) == desired_sparse
if same_key and same_name and same_options: )
return if same_key and same_name and same_options:
await collection.drop_index(index["name"]) return
await collection.drop_index(index["name"])
await collection.create_index(keys, **options) await collection.create_index(keys, **options)