From cf3c9925e3877a1edecba8dfc2915fc47816e385 Mon Sep 17 00:00:00 2001 From: Jordi Masip Date: Tue, 4 Oct 2022 15:04:57 +0200 Subject: [PATCH] Fix content.async_get() catches KeyError exceptions unrelated to txn.get_child() (#1178) --- CHANGELOG.rst | 1 + guillotina/content.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a7e695a89..d0a0d4291 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,7 @@ CHANGELOG 6.5.0 (unreleased) ------------------ +- Fix content.async_get() catches KeyError exceptions unrelated to txn.get_child() - Deps: replace aioredis with redis-py - Deps: updated flake8 so it won't depend on 'importlib-metadata<5' [masipcat] diff --git a/guillotina/content.py b/guillotina/content.py index e92aa5c18..911d89ce2 100644 --- a/guillotina/content.py +++ b/guillotina/content.py @@ -327,12 +327,12 @@ async def async_get(self, key: str, default=None, suppress_events=False) -> Opti try: txn = self._get_transaction() val = await txn.get_child(self, key) - if val is not None: - if not suppress_events: - await notify(ObjectLoadedEvent(val)) - return val except KeyError: - pass + val = None + if val is not None: + if not suppress_events: + await notify(ObjectLoadedEvent(val)) + return val return default async def async_multi_get(