Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[external-assets] Hoist resolution of input asset keys to RepositoryDataBuilder #20186

Conversation

smackesey
Copy link
Collaborator

@smackesey smackesey commented Mar 1, 2024

Summary & Motivation

We have some hairy logic that resolves "relative" asset keys associated with asset inputs. Currently this resolution is done in multiple internal places, which complicates internal codepaths dealing with assets.

This PR hoists resolution to repository build time, in the same place that we convert source assets to assets def. This simplifies internal pathways.

In order to support this change, I had to alter tests that were directly calling UnresolvedAssetsJobDefinition.resolve with an AssetGraph to instead go through repository construction. With the external asset conversion happening at the repo level, this is something that needed to be done anyway.

How I Tested These Changes

Existing test suite

@smackesey smackesey force-pushed the sean/external-assets-asset-graph-tweaks branch from 2c4a5a8 to 0625561 Compare March 1, 2024 16:36
@smackesey smackesey force-pushed the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch from 66ff903 to 00eb64c Compare March 1, 2024 16:36
@smackesey smackesey marked this pull request as ready for review March 1, 2024 17:57
@smackesey smackesey requested review from schrockn and sryza March 1, 2024 17:57
@smackesey smackesey force-pushed the sean/external-assets-asset-graph-tweaks branch from 0625561 to 58dcd97 Compare March 1, 2024 18:16
@smackesey smackesey force-pushed the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch from 00eb64c to 2f03e42 Compare March 1, 2024 18:16
@smackesey smackesey force-pushed the sean/external-assets-asset-graph-tweaks branch from 58dcd97 to 8beb90c Compare March 1, 2024 18:45
Base automatically changed from sean/external-assets-asset-graph-tweaks to master March 1, 2024 18:46
@smackesey smackesey requested a review from OwenKephart March 1, 2024 18:46
@smackesey smackesey force-pushed the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch 3 times, most recently from ae90738 to 5003390 Compare March 2, 2024 20:43
Copy link

github-actions bot commented Mar 2, 2024

Deploy preview for dagster-docs ready!

Preview available at https://dagster-docs-8nzhr4fkf-elementl.vercel.app
https://sean-external-assets-hoist-input-key-resolution-to-repo-builder.dagster.dagster-docs.io

Direct link to changed pages:

@smackesey smackesey changed the base branch from master to sean/pytest-81-compat March 3, 2024 21:40
@smackesey smackesey force-pushed the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch from 5003390 to 072ed7a Compare March 3, 2024 21:40
Base automatically changed from sean/pytest-81-compat to master March 3, 2024 22:08
@smackesey smackesey force-pushed the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch from 072ed7a to c2031ac Compare March 3, 2024 22:13
@smackesey smackesey force-pushed the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch 3 times, most recently from 9fa2ff0 to 42c75ff Compare March 4, 2024 20:29
Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An excellent change.

It would be great if we could test that AssetsDefinition has fully resolved dependencies and check invariants at appropriate entry points to ensure that they don't sneak through.

Put another way, at what point is it illegal to pass in an AssetsDefinition to one of our APIs?

Comment on lines 729 to 744
def resolve_asset_job(
assets: Sequence[Union[AssetsDefinition, SourceAsset]],
*,
selection: Optional[CoercibleToAssetSelection] = None,
name: str = "asset_job",
resources: Mapping[str, object] = {},
**kwargs: Any,
) -> JobDefinition:
assets_defs = [a for a in assets if isinstance(a, AssetsDefinition)]
source_assets = [a for a in assets if isinstance(a, SourceAsset)]
selection = selection or assets_defs
return Definitions(
assets=[*assets_defs, *source_assets],
jobs=[define_asset_job(name, selection, **kwargs)],
resources=resources,
).get_job_def(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why call this "resolve" asset job?

create_asset_job_from_assets? or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, it was bc we are getting the result of define_asset_job(...).resolve(...) but "resolution" here is kind of an implementation detail. Changed to create_test_asset_job.

@smackesey smackesey force-pushed the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch from 42c75ff to 5401f3b Compare March 4, 2024 21:07
@smackesey
Copy link
Collaborator Author

smackesey commented Mar 4, 2024

It would be great if we could test that AssetsDefinition has fully resolved dependencies and check invariants at appropriate entry points to ensure that they don't sneak through.

I think all of our public APIs go through a Definitions object and thus an AssetGraph. That's the goal anyway, for all public APIs to pass through asset graph normalization. That should guarantee we are always dealing with resolved dependencies.

@smackesey smackesey merged commit fed7b80 into master Mar 4, 2024
1 check was pending
@smackesey smackesey deleted the sean/external-assets-hoist-input-key-resolution-to-repo-builder branch March 4, 2024 21:25
PedramNavid pushed a commit that referenced this pull request Mar 28, 2024
…ataBuilder (#20186)

## Summary & Motivation

We have some hairy logic that resolves "relative" asset keys associated
with asset inputs. Currently this resolution is done in multiple
internal places, which complicates internal codepaths dealing with
assets.

This PR hoists resolution to repository build time, in the same place
that we convert source assets to assets def. This simplifies internal
pathways.

In order to support this change, I had to alter tests that were directly
calling `UnresolvedAssetsJobDefinition.resolve` with an `AssetGraph` to
instead go through repository construction. With the external asset
conversion happening at the repo level, this is something that needed to
be done anyway.

## How I Tested These Changes

Existing test suite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants