-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lazy-defs] [RFC] global DefinitionsLoadContext (#24566)
## Summary & Motivation Variant of reconstruction metadata API where, instead of definitions being "lazily" defined in a function, they continue to be defined using a standard `Definitions` instantiation. A `DefinitionsLoadContext` instance is made available via `DefinitionsLoadContext.get()`-- this is set prior to loading a repository. The upshot is that users do not have to change their entry point code. Integrations can invoke `DefinitionsLoadContext.get()` to access the context without the user having to pass it in. ## How I Tested These Changes New unit tests. ## Changelog NOCHANGELOG - [ ] `NEW` _(added new feature or capability)_ - [ ] `BUGFIX` _(fixed a bug)_ - [ ] `DOCS` _(added or updated documentation)_
- Loading branch information
Showing
4 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
python_modules/dagster/dagster_tests/definitions_tests/metadata_defs_global_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from dagster._core.definitions.asset_spec import AssetSpec | ||
from dagster._core.definitions.decorators.asset_decorator import asset | ||
from dagster._core.definitions.definitions_class import Definitions | ||
from dagster._core.definitions.definitions_loader import DefinitionsLoadContext, DefinitionsLoadType | ||
from dagster._core.definitions.external_asset import external_assets_from_specs | ||
|
||
from dagster_tests.definitions_tests.test_definitions_loader import fetch_foo_integration_asset_info | ||
|
||
FOO_INTEGRATION_SOURCE_KEY = "foo_integration" | ||
|
||
WORKSPACE_ID = "my_workspace" | ||
|
||
|
||
# This function would be provided by integration lib dagster-foo | ||
def _get_foo_integration_defs(workspace_id: str) -> Definitions: | ||
context = DefinitionsLoadContext.get() | ||
metadata_key = f"{FOO_INTEGRATION_SOURCE_KEY}/{workspace_id}" | ||
if ( | ||
context.load_type == DefinitionsLoadType.RECONSTRUCTION | ||
and metadata_key in context.reconstruction_metadata | ||
): | ||
payload = context.reconstruction_metadata[metadata_key] | ||
else: | ||
payload = fetch_foo_integration_asset_info(workspace_id) | ||
asset_specs = [AssetSpec(item["id"]) for item in payload] | ||
assets = external_assets_from_specs(asset_specs) | ||
return Definitions( | ||
assets=assets, | ||
).with_reconstruction_metadata({metadata_key: payload}) | ||
|
||
|
||
@asset | ||
def regular_asset(): ... | ||
|
||
|
||
defs = Definitions.merge( | ||
_get_foo_integration_defs(WORKSPACE_ID), | ||
Definitions(assets=[regular_asset]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters