Skip to content

Commit 96b1480

Browse files
committed
dev:minimal WoRMS compatibility: mypy fix
1 parent 6035d60 commit 96b1480

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

py/API_operations/TaxoManager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,12 @@ def pull_updates(self) -> Dict[str, Any]:
598598
for a_col in self.UpdatableCols:
599599
setattr(taxon, a_col, a_json_taxon[a_col])
600600
taxon.lastupdate_datetime = lastupdate_datetime
601+
# TODO: Below is mandatory as we alter trigger for fast deletion
602+
# But we lose, in case of failure, the facility to re-sync, which is based on last
603+
# updated date of taxonomy entries, nothing for deletes here.
604+
self.session.commit()
601605
if len(to_delete) > 0:
602606
TaxonomyBO.do_deletes(self.session, to_delete)
603-
self.session.commit()
604607

605608
# if gvp('updatestat') == 'Y':
606609
# msg = DoSyncStatUpdate()

py/BO/Taxonomy.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -432,24 +432,27 @@ def do_deletes(cls, session: Session, to_delete: List[ClassifIDT]) -> None:
432432
# * **`taxonomy.parent_id`**: Although not explicitly defined with a `ForeignKey` constraint in the SQLAlchemy model (it is a simple `INTEGER` column), it logically points to `taxonomy.id` to represent the taxonomic tree structure.
433433
# * **`taxonomy.rename_to`**: Similarly, this `INTEGER` column is used to store an "advised" target taxon for mass category changes, logically referring to another `taxonomy.id`.
434434
# * **`taxo_recast.transforms`**: This `JSONB` column stores mapping in the form `{from:to}`, where both values are taxonomic IDs, though they are not enforced by database-level foreign key constraints.
435-
435+
sql = text("SELECT DISTINCT id FROM taxonomy")
436+
res: Result = session.execute(sql, {"een": list(to_delete)})
437+
present = {an_id for an_id, in res}
438+
final_delete = present.intersection(to_delete)
436439
# We want to protect 1. and 2.
437-
logger.info("Taxo delete, list: %s", to_delete)
440+
logger.info("Taxo delete, list: %s", final_delete)
438441
sql = text("SELECT DISTINCT objid FROM obj_head WHERE classif_id = ANY (:een)")
439-
res: Result = session.execute(sql, {"een": list(to_delete)})
440-
prevent_obj_head = {an_id for an_id, in res}
442+
res2: Result = session.execute(sql, {"een": list(final_delete)})
443+
prevent_obj_head = {an_id for an_id, in res2}
441444
if len(prevent_obj_head) > 0:
442445
logger.error("Unsafe deletion due to objects %s", prevent_obj_head)
443446
sql = text("SELECT DISTINCT objid FROM objectsclassifhisto WHERE classif_id = ANY (:een)")
444-
res: Result = session.execute(sql, {"een": list(to_delete)})
445-
prevent_obj_histo = {an_id for an_id, in res}
447+
res3: Result = session.execute(sql, {"een": list(final_delete)})
448+
prevent_obj_histo = {an_id for an_id, in res3}
446449
if len(prevent_obj_histo) > 0:
447450
logger.error("Unsafe deletion due to objects history %s", prevent_obj_histo)
448451
# assert len(prevent_obj_head) == 0 and len(prevent_obj_histo) == 0, "Cannot achieve safe deletion"
449452
logger.info("deleting categories")
450453
session.execute(text("alter table taxonomy disable trigger all"))
451454
try:
452-
for a_taxon in to_delete:
455+
for a_taxon in final_delete:
453456
logger.info("deleting category %s", a_taxon)
454457
taxon = session.query(Taxonomy).get(a_taxon)
455458
session.delete(taxon)

0 commit comments

Comments
 (0)