Skip to content

Commit

Permalink
Merge pull request #2677 from camptocamp/backport/2675-to-master
Browse files Browse the repository at this point in the history
[Backport master] Prevent error on postgresql_id attribute
  • Loading branch information
sbrunner authored Dec 20, 2024
2 parents 16c28f7 + 99b0ba4 commit e222762
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 e222762

Please sign in to comment.