From d473b5d83652e8128924d8b3ee01ec76e194a44b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 22 Apr 2023 10:40:26 +0200 Subject: [PATCH] Make the recursive entity merger/column set logic more resilient against ObjectDeletedError --- platypush/entities/_engine/repo/merger.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/platypush/entities/_engine/repo/merger.py b/platypush/entities/_engine/repo/merger.py index 4297dd51c..71b344c21 100644 --- a/platypush/entities/_engine/repo/merger.py +++ b/platypush/entities/_engine/repo/merger.py @@ -1,11 +1,15 @@ +import logging from typing import Iterable, List, Optional from sqlalchemy.orm import Session +from sqlalchemy.orm.exc import ObjectDeletedError from platypush.entities._base import Entity, EntityMapping from .helpers import get_parent +logger = logging.getLogger(__name__) + # pylint: disable=too-few-public-methods class EntitiesMerger: @@ -180,7 +184,13 @@ class EntitiesMerger: **(entity.meta or {}), # type: ignore } elif col not in ('id', 'created_at'): - setattr(existing_entity, col, getattr(entity, col)) + try: + setattr(existing_entity, col, getattr(entity, col)) + except ObjectDeletedError as e: + logger.warning( + 'Could not set %s on entity <%s>: %s', + col, existing_entity.entity_key, e + ) # Recursive call to merge the columns of the children too if include_children: