diff --git a/arkindex_worker/.ruff.toml b/arkindex_worker/.ruff.toml index b5aed0e63c220137aaf1429b3daedc135935e407..4263ea9052a2d62e215e40e9d262a71aeaba5aca 100644 --- a/arkindex_worker/.ruff.toml +++ b/arkindex_worker/.ruff.toml @@ -38,3 +38,7 @@ ignore = [ "__init__.py" = [ "G001", # Logging statement uses `string.format()` ] +"worker/__init__.py" = [ + "SIM105", # Use `contextlib.suppress(Exception)` instead of try-except-pass + "S110", # `try`-`except`-`pass` detected, consider logging the exception +] diff --git a/arkindex_worker/cache.py b/arkindex_worker/cache.py index 6b43f47a9590b4c41a19637e6518014e863e592d..9157e049b18ce646282310150ca74c1c1cac86be 100644 --- a/arkindex_worker/cache.py +++ b/arkindex_worker/cache.py @@ -6,6 +6,7 @@ On methods that support caching, the database will be used for all reads, and writes will go both to the Arkindex API and the database, reducing network usage. """ + import json from pathlib import Path import sqlite3 @@ -322,8 +323,9 @@ def merge_parents_cache(paths: list, current_database: Path): # Check that the parent cache uses a compatible version check_version(path) - with SqliteDatabase(path) as source, source.bind_ctx(MODELS): - source.create_tables(MODELS) + with SqliteDatabase(path) as source: + with source.bind_ctx(MODELS): + source.create_tables(MODELS) logger.info(f"Merging parent db {path} into {current_database}") statements = [ diff --git a/arkindex_worker/worker/__init__.py b/arkindex_worker/worker/__init__.py index f98bc77c61ab4b4c7984deae35918126df080a8b..405ab24bfa3553d23b51191f759b26f8e0d852a6 100644 --- a/arkindex_worker/worker/__init__.py +++ b/arkindex_worker/worker/__init__.py @@ -3,7 +3,6 @@ Base classes to implement Arkindex workers. """ -import contextlib from enum import Enum import json import os @@ -21,7 +20,7 @@ from arkindex_worker.worker.base import BaseWorker from arkindex_worker.worker.classification import ClassificationMixin from arkindex_worker.worker.element import ElementMixin from arkindex_worker.worker.entity import EntityMixin -from arkindex_worker.worker.metadata import MetaDataMixin +from arkindex_worker.worker.metadata import MetaDataMixin, MetaType # noqa: F401 from arkindex_worker.worker.transcription import TranscriptionMixin from arkindex_worker.worker.version import WorkerVersionMixin @@ -229,9 +228,10 @@ class ElementsWorker( ) if element: # Try to update the activity to error state regardless of the response - with contextlib.suppress(Exception): + try: self.update_activity(element.id, ActivityState.Error) - + except Exception: + pass self.report.error(element_id, e) # Save report as local artifact diff --git a/tests/test_elements_worker/test_metadata.py b/tests/test_elements_worker/test_metadata.py index 25e58267b2ec8369ebe5b69ea7a9caf09dd26c28..5507b30ddd55c98f0495323abb823c808460e5d4 100644 --- a/tests/test_elements_worker/test_metadata.py +++ b/tests/test_elements_worker/test_metadata.py @@ -7,7 +7,7 @@ import pytest from arkindex.mock import MockApiClient from arkindex_worker.cache import CachedElement from arkindex_worker.models import Element -from arkindex_worker.worker.metadata import MetaType +from arkindex_worker.worker import MetaType from . import BASE_API_CALLS