Skip to content

Commit

Permalink
tag no value
Browse files Browse the repository at this point in the history
branch-name: tag-no-value
  • Loading branch information
sryza committed Mar 18, 2024
1 parent 7673295 commit 3b5f6af
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions python_modules/dagster/dagster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@
from dagster._core.storage.tags import (
MAX_RUNTIME_SECONDS_TAG as MAX_RUNTIME_SECONDS_TAG,
MEMOIZED_RUN_TAG as MEMOIZED_RUN_TAG,
TAG_NO_VALUE as TAG_NO_VALUE,
)
from dagster._core.storage.upath_io_manager import UPathIOManager as UPathIOManager
from dagster._core.types.config_schema import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
fetch_sources,
parse_clause,
)
from dagster._core.storage.tags import TAG_NO_VALUE
from dagster._serdes.serdes import whitelist_for_serdes

from .asset_check_spec import AssetCheckKey
Expand Down Expand Up @@ -195,8 +196,16 @@ def tag_string(cls, string: str, include_sources: bool = False) -> "AssetSelecti
include_sources (bool): If True, then include source assets matching the group in the
selection.
"""
key, value = string.split("=")
return TagAssetSelection(key=key, value=value, include_sources=include_sources)
split_by_equals_segments = string.split("=")
if len(split_by_equals_segments) == 1:
return TagAssetSelection(
key=string, value=TAG_NO_VALUE, include_sources=include_sources
)
elif len(split_by_equals_segments) == 2:
key, value = split_by_equals_segments
return TagAssetSelection(key=key, value=value, include_sources=include_sources)
else:
check.failed(f"Invalid tag selection string: {string}. Must have no more than one '='.")

@public
@staticmethod
Expand Down
3 changes: 3 additions & 0 deletions python_modules/dagster/dagster/_core/storage/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
]


TAG_NO_VALUE = "__dagster_novalue"


class TagType(Enum):
# Custom tag provided by a user
USER_PROVIDED = "USER_PROVIDED"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
from dagster import (
TAG_NO_VALUE,
AssetIn,
AssetOut,
AssetSpec,
Expand Down Expand Up @@ -711,6 +712,7 @@ def test_deserialize_old_all_asset_selection():

def test_from_string_tag():
assert AssetSelection.from_string("tag:foo=bar") == AssetSelection.tag("foo", "bar")
assert AssetSelection.from_string("tag:foo") == AssetSelection.tag("foo", TAG_NO_VALUE)


def test_tag():
Expand All @@ -736,10 +738,18 @@ def test_tag_string():
AssetSpec("asset2", tags={"foo": "fooval2"}),
AssetSpec("asset3", tags={"foo": "fooval", "bar": "barval"}),
AssetSpec("asset4", tags={"bar": "barval"}),
AssetSpec("asset5", tags={"baz": TAG_NO_VALUE}),
AssetSpec("asset6", tags={"baz": TAG_NO_VALUE, "bar": "barval"}),
]
)
def assets(): ...

assert AssetSelection.tag_string("foo=fooval").resolve([assets]) == {
AssetKey(k) for k in ["asset1", "asset3"]
AssetKey("asset1"),
AssetKey("asset3"),
}
assert AssetSelection.tag_string("foo").resolve([assets]) == set()
assert AssetSelection.tag_string("baz").resolve([assets]) == {
AssetKey("asset5"),
AssetKey("asset6"),
}

0 comments on commit 3b5f6af

Please sign in to comment.