-
Notifications
You must be signed in to change notification settings - Fork 17.1k
Thread version_data through BundleInfo to worker-side bundle initialization #67217
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
base: main
Are you sure you want to change the base?
Changes from all commits
147a06f
be30b30
d4477f6
c3a1fe9
854b27b
a345f69
87dd9a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -324,19 +324,24 @@ def _extract_template_params(bundle_instance: BaseDagBundle) -> dict: | |
|
|
||
| return params | ||
|
|
||
| def get_bundle(self, name: str, version: str | None = None) -> BaseDagBundle: | ||
| def get_bundle( | ||
| self, name: str, version: str | None = None, version_data: dict | None = None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: type drift across the three layers. |
||
| ) -> BaseDagBundle: | ||
| """ | ||
| Get a DAG bundle by name. | ||
|
|
||
| :param name: The name of the DAG bundle. | ||
| :param version: The version of the DAG bundle you need (optional). If not provided, ``tracking_ref`` will be used instead. | ||
| :param version_data: Optional structured data associated with this version (e.g., S3 manifest). | ||
|
|
||
| :return: The DAG bundle. | ||
| """ | ||
| cfg_bundle = self._bundle_config.get(name) | ||
| if not cfg_bundle: | ||
| raise ValueError(f"Requested bundle '{name}' is not configured.") | ||
| return cfg_bundle.bundle_class(name=name, version=version, **cfg_bundle.kwargs) | ||
| return cfg_bundle.bundle_class( | ||
| name=name, version=version, version_data=version_data, **cfg_bundle.kwargs | ||
| ) | ||
|
|
||
| def get_all_dag_bundles(self) -> Iterable[BaseDagBundle]: | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| import os | ||
| from abc import ABC, abstractmethod | ||
| from collections.abc import Hashable | ||
| from typing import TYPE_CHECKING | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field | ||
|
|
||
|
|
@@ -66,6 +66,7 @@ class BundleInfo(BaseModel): | |
|
|
||
| name: str | ||
| version: str | None = None | ||
| version_data: dict[str, Any] | None = None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Worth one of: a docstring with a soft size cap, a Pydantic validator that warns above a threshold, or a documented side-channel pattern (S3 URL pointer + worker fetch) before any consumer ships a manifest-style payload here. |
||
|
|
||
|
|
||
| class BaseWorkloadSchema(BaseModel): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,9 +118,13 @@ def make( | |
|
|
||
| ser_ti = TaskInstanceDTO.model_validate(ti, from_attributes=True) | ||
| if not bundle_info: | ||
| version_data = None | ||
| if ti.dag_version is not None and ti.dag_run.bundle_version is not None: | ||
| version_data = ti.dag_version.version_data | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why of this read off ti, but other things just below are ti.dag_model.bundle*
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth flagging that even off the same
The scheduler picks a deliberate rule for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ashb - What we're passing along here is the version that is being used and the bundle to use to grab it. The bundle itself isn't tracking the current version of the dag, that's on the dag_version. So once on the worker side, we'll ask the bundle to load the state of the bundle for the specific version the dag is trying to run with. So properties from these two things are combined later. Does that make sense? @kaxil Fair point, I think the right rule is: version_data should only be populated when the run is pinned (i.e., dag_run.bundle_version is not None). If the run is unpinned, the worker should use the latest bundle state anyway, so sending stale version_data would be misleading. I'll add a guard: version_data = None
if ti.dag_version is not None and ti.dag_run.bundle_version is not None:
version_data = ti.dag_version.version_data This mirrors the existing rule for bundle_version at scheduler_job_runner.py:1438-1442. For the second case the |
||
| bundle_info = BundleInfo( | ||
| name=ti.dag_model.bundle_name, | ||
| version=ti.dag_run.bundle_version, | ||
| version_data=version_data, | ||
| ) | ||
| fname = log_filename_template_renderer()(ti=ti) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -650,6 +650,7 @@ def _executable_task_instances_to_queued(self, max_tis: int, session: Session) - | |
| ranked_query.c.map_index_for_ordering, | ||
| ) | ||
| .options(selectinload(TI.dag_model)) | ||
| .options(selectinload(TI.dag_version)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, joins aren't free, and this isn't used for most places. I'm wondering if this needs to be based on what the bundle backend needs somehow?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. selectinload uses a single additional SELECT batched across all tis in the result set (not n sized query), so the cost is one extra round-trip per scheduler loop iteration rather than per ti. It's hard to make it conditional because we're working with a bunch of tis that are mixed between versioned bundles and not. We could do a lazy load later, but then it becomes many requests, one for each TI lazy loaded. I think the impact here is pretty minimal given the single extra batched select (no new joins are happening here now)?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This selectinload matters because TIs go through Also flagging: this adds a second selectinload inside the |
||
| ) | ||
|
|
||
| query = query.limit(max_tis) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,3 +323,16 @@ def test_bundle_version_inequality(self): | |
| bv1 = BundleVersion(version="abc", data={"key": "val"}) | ||
| bv2 = BundleVersion(version="abc", data={"key": "other"}) | ||
| assert bv1 != bv2 | ||
|
|
||
|
|
||
| def test_version_data_stored_on_bundle(): | ||
| """Test that version_data passed to a bundle constructor is stored on the instance.""" | ||
| manifest = {"schema_version": 1, "files": {"dags/my_dag.py": "S3VersionId123"}} | ||
| bundle = BasicBundle(name="test", version="abc", version_data=manifest) | ||
| assert bundle.version_data == manifest | ||
|
|
||
|
|
||
| def test_version_data_defaults_to_none(): | ||
| """Test that version_data defaults to None when not provided.""" | ||
| bundle = BasicBundle(name="test") | ||
| assert bundle.version_data is None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two tests verify the constructor stores Worth a test that builds a TI with |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.