Skip to content

Commit

Permalink
throw error for empty asset key (#8069)
Browse files Browse the repository at this point in the history
  • Loading branch information
smackesey committed May 25, 2022
1 parent 84ccc32 commit ac6007c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python_modules/dagster/dagster/core/definitions/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def __new__(cls, path: Sequence[str]):
else:
path = list(check.sequence_param(path, "path", of_type=str))

check.invariant(
all(len(seg) > 0 for seg in path), "Asset key segments must be non-empty strings."
)
return super(AssetKey, cls).__new__(cls, path=path)

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import pytest

from dagster import AssetKey, AssetMaterialization, Output, job, op
from dagster._check import CheckError
from dagster.core.definitions.events import parse_asset_key_string
from dagster.core.events.log import EventLogEntry
from dagster.core.instance import DagsterInstance, InstanceRef
Expand All @@ -7,6 +10,13 @@
from dagster.utils.test import copy_directory


def test_invalid_asset_key():
with pytest.raises(CheckError):
AssetKey("")
with pytest.raises(CheckError):
AssetKey(["foo", "", "bar"])


def test_structured_asset_key():
asset_parsed = AssetKey(parse_asset_key_string("(Hello)"))
assert len(asset_parsed.path) == 1
Expand Down

0 comments on commit ac6007c

Please sign in to comment.