Skip to content

Commit

Permalink
Prevent error on postgresql_id attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 20, 2024
1 parent 7f24e2c commit 3593681
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions tilecloud_chain/store/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -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
Expand Down

0 comments on commit 3593681

Please sign in to comment.