-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[module-loaders] Genericize object list functionality to take in all sensors, jobs, schedules #26545
[module-loaders] Genericize object list functionality to take in all sensors, jobs, schedules #26545
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
f2e7f3d
to
a67444d
Compare
4b0a6f9
to
6b95559
Compare
a67444d
to
fa8dff1
Compare
6b95559
to
85e25a2
Compare
python_modules/dagster/dagster/_core/definitions/module_loaders/utils.py
Outdated
Show resolved
Hide resolved
RuntimeKeyScopedAssetObjectTypes = (AssetsDefinition, AssetSpec, SourceAsset) | ||
RuntimeAssetObjectTypes = (AssetsDefinition, AssetSpec, SourceAsset, CacheableAssetsDefinition) | ||
RuntimeDagsterObjectTypes = RuntimeAssetObjectTypes # For now | ||
RuntimeScheduleObjectTypes = (ScheduleDefinition, UnresolvedPartitionedAssetScheduleDefinition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This structure looks pretty annoying to maintain.
I've run into this annoyance myself, but it does look like get_args(Union[x, y, z])
(imported from typing) would return a tuple of (x, y, z), which we could use for the runtime type checking, which would eliminate this sort of duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah nice. That seems acceptable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to follow up on this; I think that the get_args approach doesn't actually work with type introspection in pylance; so I think this solution is no longer acceptable. I agree that it's annoying to maintain but I don't think it's that annoying
python_modules/dagster/dagster/_core/definitions/module_loaders/utils.py
Outdated
Show resolved
Hide resolved
|
||
LoadableAssetObject = Union[AssetsDefinition, AssetSpec, SourceAsset, CacheableAssetsDefinition] | ||
LoadableDagsterObject = LoadableAssetObject # For now | ||
ScheduleDefinitionObject = Union[ScheduleDefinition, UnresolvedPartitionedAssetScheduleDefinition] | ||
JobDefinitionObject = Union[JobDefinition, UnresolvedAssetJobDefinition] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe:
LoadableAssetDef
LoadableScheduleDef
LoadableJobDef
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LoadableAssetDef I think is particularly confusing given that it can be a SourceAsset or AssetSpec, for example
fa8dff1
to
d8e8a8f
Compare
85e25a2
to
46ad68c
Compare
d8e8a8f
to
01f281a
Compare
46ad68c
to
b2b3568
Compare
01f281a
to
f7eb224
Compare
b2b3568
to
3b1694b
Compare
f7eb224
to
3942aa6
Compare
d0c31d4
to
bccf07d
Compare
f1016a1
to
2b7cdbb
Compare
6cb2f15
to
498fa70
Compare
2b7cdbb
to
d2db161
Compare
498fa70
to
c8a751e
Compare
d2db161
to
6bc53ed
Compare
c8a751e
to
bbc7c21
Compare
6bc53ed
to
a1e7c18
Compare
bbc7c21
to
fc5fbc5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should abandon this RuntimeObjectType / LoadableXObject conceptual thing and just write things out explicitly for now.
This buys us a few saved lines of code at the cost of two new conceptual categories that need to be kept in sync with eachother anyway.
@cached_property | ||
def schedule_defs(self) -> Sequence[ScheduleDefinitionObject]: | ||
return [ | ||
asset for asset in self.deduped_objects if isinstance(asset, RuntimeScheduleObjectTypes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't do this automatically then I would much prefer putting the types here explicitly rather than importing the type tuple from elsewhere.
So that would at least be replacing RuntimeScheduleObjectTypes with the explicit (ScheduleDefinition, UnresolvedPartitionedAssetScheduleDefinition)
I also think ScheduleDefinitionObject is confusing enough of a name that we should probably just put the Union[ScheduleDefinition, UnresolvedPartitionAssetScheduleDefinition] there as well.
This is actually not any more redundant than the current solution and localizes the redundancy so it's easier to wrap your head around (and doesn't require the creation of a new concept).
The only place where this adds more LoC is the LoadableDagsterObject bit (where we do need to re-list all of these types), which I think is acceptable.
I'd rather spend the lines of code and keep everything in one file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough
a1e7c18
to
e9d0bba
Compare
fc5fbc5
to
d42506a
Compare
e9d0bba
to
b1f2469
Compare
d42506a
to
4591c5c
Compare
b1f2469
to
d4430a7
Compare
4591c5c
to
3c41b3c
Compare
d4430a7
to
3f706f1
Compare
3c41b3c
to
429aa3a
Compare
3f706f1
to
73810c7
Compare
429aa3a
to
ba32822
Compare
0405939
to
ca38954
Compare
ba32822
to
588f9ee
Compare
Summary & Motivation
Actually genericize
ModuleScopedDagsterObjects
to handle taking in all types of Dagster objects - sensors, schedules, and jobs. I explicitly left out resources and loggers, because I don't think it makes sense to scoop those up at module load - since they need to be associated with a key.How I Tested These Changes
Added a new test file
test_module_loaders
which scaffolds out a module fake for a given test spec, and ensures that either an error is thrown or the correct number of attributes are accessible on the underlying list.