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

[module-loaders] Genericize object list functionality to take in all sensors, jobs, schedules #26545

Merged

Conversation

dpeng817
Copy link
Contributor

@dpeng817 dpeng817 commented Dec 17, 2024

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.

Copy link
Contributor Author

dpeng817 commented Dec 17, 2024

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from f2e7f3d to a67444d Compare December 18, 2024 02:52
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 4b0a6f9 to 6b95559 Compare December 18, 2024 02:53
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from a67444d to fa8dff1 Compare December 18, 2024 03:35
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 6b95559 to 85e25a2 Compare December 18, 2024 03:35
@dpeng817 dpeng817 marked this pull request as ready for review December 18, 2024 15:26
@dpeng817 dpeng817 changed the title Genericize object list functionality to take in all sensors, jobs, schedules [module-loaders] Genericize object list functionality to take in all sensors, jobs, schedules Dec 18, 2024
RuntimeKeyScopedAssetObjectTypes = (AssetsDefinition, AssetSpec, SourceAsset)
RuntimeAssetObjectTypes = (AssetsDefinition, AssetSpec, SourceAsset, CacheableAssetsDefinition)
RuntimeDagsterObjectTypes = RuntimeAssetObjectTypes # For now
RuntimeScheduleObjectTypes = (ScheduleDefinition, UnresolvedPartitionedAssetScheduleDefinition)
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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


LoadableAssetObject = Union[AssetsDefinition, AssetSpec, SourceAsset, CacheableAssetsDefinition]
LoadableDagsterObject = LoadableAssetObject # For now
ScheduleDefinitionObject = Union[ScheduleDefinition, UnresolvedPartitionedAssetScheduleDefinition]
JobDefinitionObject = Union[JobDefinition, UnresolvedAssetJobDefinition]
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe:

LoadableAssetDef
LoadableScheduleDef
LoadableJobDef

?

Copy link
Contributor Author

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

@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from fa8dff1 to d8e8a8f Compare December 18, 2024 18:03
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 85e25a2 to 46ad68c Compare December 18, 2024 18:03
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from d8e8a8f to 01f281a Compare December 18, 2024 20:24
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 46ad68c to b2b3568 Compare December 18, 2024 20:25
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from 01f281a to f7eb224 Compare December 18, 2024 20:51
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from b2b3568 to 3b1694b Compare December 18, 2024 20:51
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from f7eb224 to 3942aa6 Compare December 18, 2024 20:55
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from d0c31d4 to bccf07d Compare December 19, 2024 00:27
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from f1016a1 to 2b7cdbb Compare December 19, 2024 01:19
@dpeng817 dpeng817 force-pushed the genericize_object_list branch 2 times, most recently from 6cb2f15 to 498fa70 Compare December 19, 2024 01:51
@dpeng817 dpeng817 dismissed OwenKephart’s stale review December 19, 2024 01:51

addressed comments

@dpeng817 dpeng817 requested a review from OwenKephart December 19, 2024 01:51
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from 2b7cdbb to d2db161 Compare December 19, 2024 02:06
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 498fa70 to c8a751e Compare December 19, 2024 02:06
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from d2db161 to 6bc53ed Compare December 19, 2024 14:19
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from c8a751e to bbc7c21 Compare December 19, 2024 14:19
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from 6bc53ed to a1e7c18 Compare December 19, 2024 14:24
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from bbc7c21 to fc5fbc5 Compare December 19, 2024 14:24
Copy link
Contributor

@OwenKephart OwenKephart left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough

@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from a1e7c18 to e9d0bba Compare December 19, 2024 15:54
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from fc5fbc5 to d42506a Compare December 19, 2024 15:54
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from e9d0bba to b1f2469 Compare December 19, 2024 16:36
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from d42506a to 4591c5c Compare December 19, 2024 16:36
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from b1f2469 to d4430a7 Compare December 19, 2024 16:40
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 4591c5c to 3c41b3c Compare December 19, 2024 16:40
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from d4430a7 to 3f706f1 Compare December 19, 2024 16:41
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 3c41b3c to 429aa3a Compare December 19, 2024 16:41
@dpeng817 dpeng817 force-pushed the dpeng817/genericize_typehints_and_methods branch from 3f706f1 to 73810c7 Compare December 19, 2024 16:53
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from 429aa3a to ba32822 Compare December 19, 2024 16:53
Base automatically changed from dpeng817/genericize_typehints_and_methods to dpeng817/delete_extra_source_assets December 19, 2024 16:54
@dpeng817 dpeng817 force-pushed the dpeng817/delete_extra_source_assets branch from 0405939 to ca38954 Compare December 19, 2024 16:58
@dpeng817 dpeng817 force-pushed the genericize_object_list branch from ba32822 to 588f9ee Compare December 19, 2024 16:58
@dpeng817 dpeng817 merged commit 620c297 into dpeng817/delete_extra_source_assets Dec 19, 2024
1 check failed
@dpeng817 dpeng817 deleted the genericize_object_list branch December 19, 2024 17:07
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