From 57e4fd5185b0f38029d648e7d4454eb47e23c527 Mon Sep 17 00:00:00 2001 From: Sam Hardwick Date: Mon, 22 Jan 2024 11:28:02 +0200 Subject: [PATCH] On ConnectionError, try to get protected corpora from cache --- korp.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/korp.py b/korp.py index b5d9b4b..2302b8c 100644 --- a/korp.py +++ b/korp.py @@ -3579,11 +3579,19 @@ def get_protected_corpora(corpora): # callbacks typically add protected corpora to an initially empty list # On failure, consider all corpora protected try: - protected = (korppluginlib.KorpCallbackPluginCaller - .filter_value_for_request("filter_protected_corpora", - protected)) + protected = korppluginlib.KorpCallbackPluginCaller.filter_value_for_request( + "filter_protected_corpora", protected + ) except ConnectionError: - return corpora + # If we can't connect, trust the cache if available + with mc_pool.reserve() as mc: + result = mc.get("%s:info_%s" % (cache_prefix(), int(strict))) + if result: + return result["protected_corpora"] + else: + # If all else fails, consider evenrything protected. + # This will crash Korp until the PUB-authentication bug is fixed. + return corpora return protected