@@ -444,7 +444,9 @@ def arg_to_cache_key(arg: Hashable) -> Hashable:
444
444
deferred : "defer.Deferred[Any]" = defer .Deferred ()
445
445
deferreds_map [arg ] = deferred
446
446
key = arg_to_cache_key (arg )
447
- cache .set (key , deferred , callback = invalidate_callback )
447
+ cached_defers .append (
448
+ cache .set (key , deferred , callback = invalidate_callback )
449
+ )
448
450
449
451
def complete_all (res : Dict [Hashable , Any ]) -> None :
450
452
# the wrapped function has completed. It returns a
@@ -455,28 +457,23 @@ def complete_all(res: Dict[Hashable, Any]) -> None:
455
457
deferreds_map [e ].callback (val )
456
458
results [e ] = val
457
459
458
- def errback (f : Failure ) -> Failure :
459
- # the wrapped function has failed. Invalidate any cache
460
- # entries we're supposed to be populating, and fail
461
- # their deferreds.
462
- for e in missing :
463
- key = arg_to_cache_key (e )
464
- cache .invalidate (key )
465
- deferreds_map [e ].errback (f )
466
-
467
- # return the failure, to propagate to our caller.
468
- return f
460
+ def errback_all (f : Failure ) -> None :
461
+ # the wrapped function has failed. Propagate the failure into
462
+ # the cache, which will invalidate the entry, and cause the
463
+ # relevant cached_deferreds to fail, which will propagate the
464
+ # failure to our caller.
465
+ for d1 in deferreds_map .values ():
466
+ d1 .errback (f )
469
467
470
468
args_to_call = dict (arg_dict )
471
469
# copy the missing set before sending it to the callee, to guard against
472
470
# modification.
473
471
args_to_call [self .list_name ] = tuple (missing )
474
472
475
- cached_defers .append (
476
- defer .maybeDeferred (
477
- preserve_fn (self .orig ), ** args_to_call
478
- ).addCallbacks (complete_all , errback )
479
- )
473
+ # dispatch the call, and attach the two handlers
474
+ defer .maybeDeferred (
475
+ preserve_fn (self .orig ), ** args_to_call
476
+ ).addCallbacks (complete_all , errback_all )
480
477
481
478
if cached_defers :
482
479
d = defer .gatherResults (cached_defers , consumeErrors = True ).addCallbacks (
0 commit comments