From 3593681c1a6fccc659c9e4f26e510a1c27d3e698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Fri, 20 Dec 2024 11:07:10 +0100 Subject: [PATCH] Prevent error on postgresql_id attribute --- tilecloud_chain/store/postgresql.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tilecloud_chain/store/postgresql.py b/tilecloud_chain/store/postgresql.py index fa3908077..5a7a8dcdb 100644 --- a/tilecloud_chain/store/postgresql.py +++ b/tilecloud_chain/store/postgresql.py @@ -590,10 +590,23 @@ def delete_one(self, tile: Tile) -> Tile: with self.SessionMaker() as session: if tile.error: if isinstance(tile.error, Exception): - _LOGGER.warning("Error while processing the tile %s", tile, exc_info=tile.error) + _LOGGER.warning( + "Error while processing the tile %s %s", + tile.tilecoord, + tile.formated_metadata, + exc_info=tile.error, + ) + + if not hasattr(tile, "postgresql_id"): + _LOGGER.error( + "The tile %s %s does not have the postgresql_id attribute", + tile.tilecoord, + tile.formated_metadata, + ) + return tile sqlalchemy_tile = ( session.query(Queue) - .where(and_(Queue.status == _STATUS_PENDING, Queue.id == tile.postgresql_id)) # type: ignore[attr-defined] + .where(and_(Queue.status == _STATUS_PENDING, Queue.id == tile.postgresql_id)) .with_for_update(of=Queue) .first() ) @@ -602,8 +615,16 @@ def delete_one(self, tile: Tile) -> Tile: sqlalchemy_tile.error = str(tile.error) # type: ignore[assignment] session.commit() else: + if not hasattr(tile, "postgresql_id"): + _LOGGER.error( + "The tile %s %s does not have the postgresql_id attribute", + tile.tilecoord, + tile.formated_metadata, + ) + return tile + session.query(Queue).where( - and_(Queue.status == _STATUS_PENDING, Queue.id == tile.postgresql_id) # type: ignore[attr-defined] + and_(Queue.status == _STATUS_PENDING, Queue.id == tile.postgresql_id) ).delete() session.commit() return tile