Hey Dagster Team, Do asset_groups constitute a na...
# ask-community
Hey Dagster Team, Do asset_groups constitute a namespace for a given asset / asset_key? E.g. if I have an asset with asset_key="asset_1", if I generate an asset materialization and attach an asset_group to it (say "group_1") and a diff group (say "group 2"). How is this expected to be handled? What's the desired pattern here for situations like the above that fits best with how dagster is designed? Should I be using a prefix such that I have [client], [asset_name]? Should I be using a partition that stores the asset separately? Or some other method? (Also is there anyway to grab an asset selection that only matches on one level of the asset_key and not the rest / prefixes? E.g. if I have "parent1/child1", "parent2/child1", "parent1/child2", if I want an asset selection that matches for any that have "child1" or if I want to match on only keys that have "parent1"? Thanks!
Hi Selene! Asset groups don't constitute a namespace. Depending on how much separation you want between your clients, you could consider multiple code locations or deployments. And for your second question: Not out of the box, but we do hear this often enough that we consider implementing it. In the meanwhile, here's a snippet that we sometimes offer that shows you a pattern on how to select assets by their prefix.
Copy code
class AssetPrefixAssetSelection(AssetSelection):
    def __init__(self, prefix: Sequence[str]):
        self.prefix = prefix

    def resolve_inner(self, asset_graph: AssetGraph) -> AbstractSet[AssetKey]:
        keys = set()
        for asset_key in asset_graph.all_asset_keys:
            if asset_key.path[: len(self.prefix)] == self.prefix:
        return keys

my_selection = AssetPrefixAssetSelection(prefix=["my", "prefix"])
Hi Tim, Thank you the snippet was very helpful 🙂