memory (disco): ensure that we don't cache None in disco hashes:

Add a guard to avoid mapping `None` to a hash.
This commit is contained in:
Goffi 2026-05-03 16:47:43 +02:00
commit 1613554018

View file

@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from collections.abc import Iterable
from typing import cast
from typing import TYPE_CHECKING, cast
from twisted.internet.interfaces import IReactorCore
from libervia.backend import G
@ -40,6 +40,9 @@ import time
from libervia.backend.tools.utils import ensure_deferred
if TYPE_CHECKING:
from libervia.backend.core.main import LiberviaBackend
log = getLogger(__name__)
@ -73,6 +76,10 @@ class HashManager:
if hash_ in self.hashes:
log.debug("ignoring hash set: it is already known")
return
if disco_info is None:
msg = f"Cannot cache 'None' for hash {hash_}"
log.exception(msg)
raise exceptions.InternalError(msg)
self.hashes[hash_] = disco_info
self.persistent[hash_] = disco_info.toElement().toXml()
@ -107,7 +114,7 @@ class HashManager:
class Discovery:
"""Manage capabilities of entities"""
def __init__(self, host):
def __init__(self, host: "LiberviaBackend"):
self.host = host
# JID-based disco info cache, it is used for entities without XEP-0115 support or
# when something goes wrong with hash validation.