-
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
Only have one kind of context for direct invocation #17554
Conversation
) | ||
|
||
|
||
class UnboundOpExecutionContext(OpExecutionContext): | ||
"""The ``context`` object available as the first argument to a solid's compute function when | ||
class DirectInvocationOpExecutionContext(OpExecutionContext): |
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.
naming?
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 this is fine, much clearer than previous name
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.
Would like to suggest RunlessOpExecutionContext
:
- Aligns with "runless" events
- Communicates more about what makes this different from a regular
OpExecutionContext
-- contextual info about the run is missing - "Invocation" is not very self-explanatory and is overloaded-- it is used for instance when building a graph with the composition API inside
@job
(PendingNodeInvocation
) - Shorter than
DirectInvocationOpExecutionContext
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 find this thinking compelling. Would also be ok with just DirectOpExecutionContext
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.
Also relevant: #18265 (comment)
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.
but it should be since it is returned by public functions that build test contexts.
I think of it as an implementation detail "private" subclass of the real public parent class. I believe the typehints on those build test context methods are the public parent classes. It doesn't quite live up to the aspirations of being able to treat it like an OpExecutionContext
and have everything work. I do like treating it as private and being able to change it.
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.
^^ ok makes sense
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.
@schrockn do you like TestOpExecutionContext
?
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.
bump for @schrockn to weigh in on naming
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.
Aligning on DirectOpExecutionContext
. Reasoning:
- Some users do full integration tests (like calling
materialize
) in these cases they won't be getting a "test" context, but they are still in a testing setup. Direct
side steps this issue because it's for the case when you are "directly" providing a context object to an op/asset- If we realize later the name needs to be different, the impact of changing the name later is low since it's a non-exported class
been validated. | ||
""" | ||
|
||
_op_def: OpDefinition |
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 don't really understand what these were in the BoundOpExecutionContext for. I can add them to the new class though if they are needed!
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.
For historical context here - op_def
was added so that after you've actually invoked an op, you could access definition-level properties about that op on the context object itself. This is useful for the situation where you use op factories for example, and might still need to query definition-level information.
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 thought since these were on the BoundExecutionContext
that they wouldn't be accessible after invocation since the bound context gets garbage collected
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.
right - i meant during invocation.
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 ok - this should still work in the new setup
05af4f3
to
1387482
Compare
Deploy preview for dagit-storybook ready! ✅ Preview Built with commit 3096474. |
Deploy preview for dagit-core-storybook ready! ✅ Preview Built with commit 3096474. |
1116a08
to
8e5aa5a
Compare
...dagster/dagster_tests/core_tests/resource_tests/pythonic_resources/test_direct_invocation.py
Outdated
Show resolved
Hide resolved
3df3b58
to
4de29b1
Compare
f8b02ae
to
96e242d
Compare
Deploy preview for dagster-university ready! ✅ Preview Built with commit 3096474. |
96e242d
to
dee10a0
Compare
dee10a0
to
a31a3da
Compare
3096474
to
92ea8d8
Compare
Summary & Motivation
This PR merges
UnboundOpExecutionContext
andBoundOpExecutionContext
into a single object,DirectOpExecutionContext
.There are three states the
DirectOpExecutionContext
can be in:op_config
orasset_key
is not accessible. We call this state "unbound" or "not bound"op_config
) is now accessible. Additionally, the user may do things that mutate the context, like emit user events or add output metadata. We call this state "bound". This state of the context is theBoundOpExecutionContext
in the old version of the code.In order to make the distinction between these states more clear and easier to maintain for engineers, the attributes associated with each state are split into separate objects:
BoundProperties
- maintains properties that are only available when the context is bound to an asset or op execution. When the context is bound to an invocation of a particular op, theBoundProperties
object will be instantiated with the relevant properties for the context as bound to that op. At the end of execution, this object is deleted. We track the bound/unbound state of the context by the existence of theBoundProperties
object.DirectExecutionProperties
- maintains attributes that can only be mutated while the context is bound, but can be read at any time (pre or post execution). If another execution begins using the same context, theDirectExecutionProperties
object is replaced with a fresh instantiation.Previous PR that does a similar thing but wasn't merged #15083
This PR accomplishes two main goals:
AssetExecutionContext
for direct invocation since the pattern for a direct invocation context is simplified.How I Tested These Changes
new unit tests