Skip to content

Commit 803fa1c

Browse files
committed
Imporved robustness of 'yuanrong_client when calling clear'
Signed-off-by: dpj135 <958208521@qq.com>
1 parent 4636766 commit 803fa1c

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

transfer_queue/storage/clients/yuanrong_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def clear(self, keys: list[str], custom_backend_meta=None):
585585

586586
strategy_tags = custom_backend_meta
587587
routed_indexes = self._route_to_strategies(
588-
strategy_tags, lambda strategy_, item_: strategy_.supports_clear(item_)
588+
strategy_tags, lambda strategy_, item_: strategy_.supports_clear(item_), failback=True
589589
)
590590

591591
def clear_task(strategy, indexes):
@@ -598,6 +598,7 @@ def _route_to_strategies(
598598
self,
599599
items: list[Any],
600600
selector: Callable[[StorageStrategy, Any], bool],
601+
failback: bool = False,
601602
) -> dict[StorageStrategy, list[int]]:
602603
"""Groups item indices by the first strategy that supports them.
603604
@@ -610,6 +611,8 @@ def _route_to_strategies(
610611
The order must correspond to the original keys.
611612
selector: A function that determines whether a strategy supports an item.
612613
Signature: `(strategy: StorageStrategy, item: Any) -> bool`.
614+
failback: If True, items that don't match any strategy will be ignored (not included in output).
615+
If False, a ValueError will be raised for any unmatched item.
613616
614617
Returns:
615618
A dictionary mapping each active strategy to a list of indexes in `items`
@@ -622,10 +625,11 @@ def _route_to_strategies(
622625
routed_indexes[strategy].append(i)
623626
break
624627
else:
625-
raise ValueError(
626-
f"No strategy supports item of type {type(item).__name__}: {item}. "
627-
f"Available strategies: {[type(s).__name__ for s in self._strategies]}"
628-
)
628+
if not failback:
629+
raise ValueError(
630+
f"No strategy supports item of type {type(item).__name__}: {item}. "
631+
f"Available strategies: {[type(s).__name__ for s in self._strategies]}"
632+
)
629633
return routed_indexes
630634

631635
@staticmethod

0 commit comments

Comments
 (0)