|
24 | 24 | from metldata import get_transformation_registry |
25 | 25 | from metldata.transform.handling import TransformationHandler |
26 | 26 | from pydantic import UUID4, BaseModel, ConfigDict |
| 27 | +from schemapack import SchemaPackValidator |
| 28 | +from schemapack.exceptions import ValidationError |
27 | 29 | from schemapack.spec.datapack import DataPack |
28 | 30 | from schemapack.spec.schemapack import SchemaPack |
29 | 31 |
|
@@ -64,6 +66,30 @@ def __init__( |
64 | 66 |
|
65 | 67 | async def queue_unprocessed(self, aem_pack: AEMPack): |
66 | 68 | """Fetch new AEMPacks via event subscriber and put them into the queue for processing.""" |
| 69 | + # For now, just load. Reloading will be dealt with in the config lock + update ticket |
| 70 | + config = await self._config_loader.load_config_from_db() |
| 71 | + |
| 72 | + # Ensure model name exists |
| 73 | + matching_model = None |
| 74 | + for model in config.models: |
| 75 | + if model.name == aem_pack.model_name: |
| 76 | + matching_model = model |
| 77 | + break |
| 78 | + else: |
| 79 | + model_lookup_error = ValueError( |
| 80 | + f"No model with name {aem_pack.model_name} registered for AEMPack with id {aem_pack.id}." |
| 81 | + ) |
| 82 | + log.error(model_lookup_error) |
| 83 | + raise model_lookup_error |
| 84 | + |
| 85 | + # Validate DataPack against corresponding SchemaPack |
| 86 | + validator = SchemaPackValidator(schemapack=matching_model.schema_) |
| 87 | + try: |
| 88 | + validator.validate(datapack=aem_pack.data) |
| 89 | + except ValidationError as error: |
| 90 | + log.error(error) |
| 91 | + raise |
| 92 | + |
67 | 93 | await self._incoming_aem_pack_queue.queue(aem_pack) |
68 | 94 |
|
69 | 95 | async def process_aem_packs(self) -> None: |
@@ -146,9 +172,12 @@ def _traverse_graph( |
146 | 172 | routes_by_input.setdefault(route.input_model_name, []).append(route) |
147 | 173 |
|
148 | 174 | if not models_by_name.get(incoming.model_name): |
149 | | - raise ValueError( |
| 175 | + model_lookup_error = ValueError( |
150 | 176 | f"No model with name {incoming.model_name} registered for AEMPack with id {incoming.id}." |
| 177 | + + "This means a previously existing model vanished, which should not happen." |
151 | 178 | ) |
| 179 | + log.critical(model_lookup_error) |
| 180 | + raise model_lookup_error |
152 | 181 |
|
153 | 182 | # Relies on dict insertion-order guarantee. |
154 | 183 | # Avoid copying or re-sorting this dict, as that would break the traversal order. |
|
0 commit comments