Skip to content

Commit

Permalink
Further simplify asset checks path
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeng817 committed Dec 16, 2024
1 parent 1570691 commit b37696c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ def load_assets_from_modules(
"""

def _asset_filter(asset: LoadableAssetTypes) -> bool:
if isinstance(asset, AssetsDefinition) and not has_only_asset_checks(asset):
return True
if isinstance(asset, AssetsDefinition):
# We don't load asset checks with asset module loaders.
return not has_only_asset_checks(asset)
if isinstance(asset, AssetSpec):
return include_specs
return True
Expand Down Expand Up @@ -439,14 +440,6 @@ def replace_keys_in_asset(
key: key_replacements.get(key, key) for key in asset.keys_by_input_name.values()
},
)
if isinstance(asset, AssetsDefinition) and has_only_asset_checks(asset):
updated_object = AssetChecksDefinition.create(
keys_by_input_name=updated_object.keys_by_input_name,
node_def=updated_object.op,
check_specs_by_output_name=updated_object.check_specs_by_output_name,
resource_defs=updated_object.resource_defs,
can_subset=updated_object.can_subset,
)
return updated_object


Expand Down Expand Up @@ -556,14 +549,6 @@ def with_attributes(
).with_attributes(
backfill_policy=backfill_policy, freshness_policy=freshness_policy
)
if isinstance(asset, AssetChecksDefinition):
new_asset = AssetChecksDefinition.create(
keys_by_input_name=new_asset.keys_by_input_name,
node_def=new_asset.op,
check_specs_by_output_name=new_asset.check_specs_by_output_name,
resource_defs=new_asset.resource_defs,
can_subset=new_asset.can_subset,
)
return_list.append(new_asset)
elif isinstance(asset, SourceAsset):
return_list.append(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from dagster import (
AssetChecksDefinition,
AssetKey,
Definitions,
asset_check,
Expand All @@ -12,6 +11,7 @@
load_assets_from_package_module,
load_assets_from_package_name,
)
from dagster._core.definitions.asset_checks import has_only_asset_checks

from dagster_tests.definitions_tests.decorators_tests.test_asset_check_decorator import (
execute_assets_and_checks,
Expand All @@ -24,7 +24,7 @@ def test_load_asset_checks_from_modules():

checks = load_asset_checks_from_modules([checks_module])
assert len(checks) == 1
assert all(isinstance(check, AssetChecksDefinition) for check in checks)
assert all(has_only_asset_checks(check) for check in checks)

asset_check_1_key = next(iter(asset_check_1.check_keys))

Expand All @@ -51,7 +51,7 @@ def test_load_asset_checks_from_modules_prefix():

checks = load_asset_checks_from_modules([checks_module], asset_key_prefix="foo")
assert len(checks) == 1
assert all(isinstance(check, AssetChecksDefinition) for check in checks)
assert all(has_only_asset_checks(check) for check in checks)

check_key = next(iter(checks[0].check_keys))
assert check_key.asset_key == AssetKey(["foo", "asset_1"])
Expand Down Expand Up @@ -79,7 +79,7 @@ def check_in_current_module():
def test_load_asset_checks_from_current_module():
checks = load_asset_checks_from_current_module(asset_key_prefix="foo")
assert len(checks) == 1
assert all(isinstance(check, AssetChecksDefinition) for check in checks)
assert all(has_only_asset_checks(check) for check in checks)
check_key = next(iter(checks[0].check_keys))
assert check_key.name == "check_in_current_module"
assert check_key.asset_key == AssetKey(["foo", "asset_1"])
Expand All @@ -104,7 +104,7 @@ def test_load_asset_checks_from_package(load_fns):

checks = checks_load_fn(checks_module, asset_key_prefix="foo")
assert len(checks) == 2
assert all(isinstance(check, AssetChecksDefinition) for check in checks)
assert all(has_only_asset_checks(check) for check in checks)
check_key_0 = next(iter(checks[0].check_keys))
assert check_key_0.name == "asset_check_1"
assert check_key_0.asset_key == AssetKey(["foo", "asset_1"])
Expand Down

0 comments on commit b37696c

Please sign in to comment.