Skip to content
Snippets Groups Projects
Commit 8650a41f authored by Manon Blanco's avatar Manon Blanco Committed by Yoann Schneider
Browse files

Explicitely log a warning when the helper doesn't support cache

parent 5df7f268
No related branches found
No related tags found
1 merge request!490Explicitely log a warning when the helper doesn't support cache
Pipeline #159331 passed
......@@ -374,3 +374,17 @@ def merge_parents_cache(paths: list, current_database: Path):
for statement in statements:
cursor.execute(statement)
connection.commit()
def unsupported_cache(func):
def wrapper(self, *args, **kwargs):
results = func(self, *args, **kwargs)
if not (self.is_read_only or self.use_cache):
logger.warning(
f"This API helper `{func.__name__}` did not update the cache database"
)
return results
return wrapper
......@@ -6,6 +6,7 @@ from collections.abc import Iterator
from enum import Enum
from arkindex_worker import logger
from arkindex_worker.cache import unsupported_cache
from arkindex_worker.models import Dataset, Element
......@@ -68,6 +69,7 @@ class DatasetMixin:
return map(format_result, list(results))
@unsupported_cache
def update_dataset_state(self, dataset: Dataset, state: DatasetState) -> Dataset:
"""
Partially updates a dataset state through the API.
......
......@@ -9,7 +9,7 @@ from warnings import warn
from peewee import IntegrityError
from arkindex_worker import logger
from arkindex_worker.cache import CachedElement, CachedImage
from arkindex_worker.cache import CachedElement, CachedImage, unsupported_cache
from arkindex_worker.models import Element
......@@ -30,6 +30,7 @@ class MissingTypeError(Exception):
class ElementMixin:
@unsupported_cache
def create_required_types(self, element_types: list[ElementType]):
"""Creates given element types in the corpus.
......@@ -82,6 +83,7 @@ class ElementMixin:
return True
@unsupported_cache
def create_sub_element(
self,
element: Element,
......@@ -284,6 +286,7 @@ class ElementMixin:
return created_ids
@unsupported_cache
def create_element_parent(
self,
parent: Element,
......
......@@ -9,7 +9,11 @@ from warnings import warn
from peewee import IntegrityError
from arkindex_worker import logger
from arkindex_worker.cache import CachedEntity, CachedTranscriptionEntity
from arkindex_worker.cache import (
CachedEntity,
CachedTranscriptionEntity,
unsupported_cache,
)
from arkindex_worker.models import Element, Transcription
......@@ -29,6 +33,7 @@ class MissingEntityType(Exception):
class EntityMixin:
@unsupported_cache
def check_required_entity_types(
self, entity_types: list[str], create_missing: bool = True
):
......@@ -206,6 +211,7 @@ class EntityMixin:
)
return transcription_ent
@unsupported_cache
def create_transcription_entities(
self,
transcription: Transcription,
......
......@@ -5,7 +5,7 @@ ElementsWorker methods for metadata.
from enum import Enum
from arkindex_worker import logger
from arkindex_worker.cache import CachedElement
from arkindex_worker.cache import CachedElement, unsupported_cache
from arkindex_worker.models import Element
......@@ -56,6 +56,7 @@ class MetaType(Enum):
class MetaDataMixin:
@unsupported_cache
def create_metadata(
self,
element: Element | CachedElement,
......@@ -106,6 +107,7 @@ class MetaDataMixin:
return metadata["id"]
@unsupported_cache
def create_metadatas(
self,
element: Element | CachedElement,
......
......@@ -470,10 +470,17 @@ def test_run_initial_dataset_state_error(
logging.WARNING,
f"Failed running worker on dataset dataset_id: AssertionError('{error}')",
),
(
logging.ERROR,
"Ran on 1 datasets: 0 completed, 1 failed",
),
] + (
[
(
logging.WARNING,
"This API helper `update_dataset_state` did not update the cache database",
)
]
if generator
else []
) + [
(logging.ERROR, "Ran on 1 datasets: 0 completed, 1 failed"),
]
......@@ -697,7 +704,15 @@ def test_run(
] * 2
extra_logs += [
(logging.INFO, "Building Dataset (dataset_id) (1/1)"),
(
logging.WARNING,
"This API helper `update_dataset_state` did not update the cache database",
),
(logging.INFO, "Completed Dataset (dataset_id) (1/1)"),
(
logging.WARNING,
"This API helper `update_dataset_state` did not update the cache database",
),
]
else:
archive_path = (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment