From 96c8dd2e4556f208152fe45c3919bf889e17439f Mon Sep 17 00:00:00 2001 From: Sean Mackesey Date: Fri, 8 Mar 2024 09:21:22 -0500 Subject: [PATCH] [external-assets] asset checks dup check --- .../repository_definition/repository_data_builder.py | 6 ++++++ .../definitions/repository_definition/valid_definitions.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/python_modules/dagster/dagster/_core/definitions/repository_definition/repository_data_builder.py b/python_modules/dagster/dagster/_core/definitions/repository_definition/repository_data_builder.py index 8a6ba28a135e3..3c1237ae85fe4 100644 --- a/python_modules/dagster/dagster/_core/definitions/repository_definition/repository_data_builder.py +++ b/python_modules/dagster/dagster/_core/definitions/repository_definition/repository_data_builder.py @@ -50,6 +50,7 @@ from .valid_definitions import VALID_REPOSITORY_DATA_DICT_KEYS, RepositoryListDefinition if TYPE_CHECKING: + from dagster._core.definitions.asset_check_spec import AssetCheckKey from dagster._core.definitions.events import AssetKey @@ -162,6 +163,7 @@ def build_caching_repository_data_from_list( sensors: Dict[str, SensorDefinition] = {} assets_defs: List[AssetsDefinition] = [] asset_keys: Set[AssetKey] = set() + asset_check_keys: Set["AssetCheckKey"] = set() source_assets: List[SourceAsset] = [] asset_checks_defs: List[AssetChecksDefinition] = [] for definition in repository_definitions: @@ -228,6 +230,10 @@ def build_caching_repository_data_from_list( source_assets.append(definition) asset_keys.add(definition.key) elif isinstance(definition, AssetChecksDefinition): + for key in definition.keys: + if key in asset_check_keys: + raise DagsterInvalidDefinitionError(f"Duplicate asset check key: {key}") + asset_check_keys.update(definition.keys) asset_checks_defs.append(definition) else: check.failed(f"Unexpected repository entry {definition}") diff --git a/python_modules/dagster/dagster/_core/definitions/repository_definition/valid_definitions.py b/python_modules/dagster/dagster/_core/definitions/repository_definition/valid_definitions.py index e767a695a2d2e..8258d87619d4d 100644 --- a/python_modules/dagster/dagster/_core/definitions/repository_definition/valid_definitions.py +++ b/python_modules/dagster/dagster/_core/definitions/repository_definition/valid_definitions.py @@ -2,6 +2,7 @@ from typing_extensions import TypeAlias +from dagster._core.definitions.asset_checks import AssetChecksDefinition from dagster._core.definitions.graph_definition import GraphDefinition from dagster._core.definitions.job_definition import JobDefinition from dagster._core.definitions.schedule_definition import ScheduleDefinition @@ -33,6 +34,7 @@ RepositoryListDefinition: TypeAlias = Union[ "AssetsDefinition", + AssetChecksDefinition, GraphDefinition, JobDefinition, ScheduleDefinition,