-
Notifications
You must be signed in to change notification settings - Fork 1
[4/5] Introduce OperationDefinition
#16
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
Conversation
cde4a79 to
4eaba19
Compare
4e78ff3 to
f44be30
Compare
4eaba19 to
8f114f8
Compare
f44be30 to
47219c7
Compare
8f114f8 to
1189fb3
Compare
47219c7 to
4af2252
Compare
1189fb3 to
7cf8382
Compare
4af2252 to
d461e2c
Compare
7cf8382 to
a888dda
Compare
d461e2c to
48b5b5c
Compare
a888dda to
a8cd3e8
Compare
48b5b5c to
b65bae0
Compare
a8cd3e8 to
70e857c
Compare
b65bae0 to
27110ec
Compare
97078d3 to
4fa4f0e
Compare
27110ec to
4cd141d
Compare
4fa4f0e to
79c228f
Compare
OperationDefinition OperationDefinition
|
|
||
|
|
||
| def get_operation_definition( | ||
| def get_operation( |
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.
Is there a user-facing use case for this or set_operation? I see we expose this call at the module level to users. I think we'd expect them to operate on a service definition and only we would be the ones translating and setting attributes.
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.
The only known user of this library at the moment is Temporal (i.e. us, in another role). Temporal are adding additional decorators analogous to sync_operation.
Temporal use set_operation here to "officially" attach the nexusrpc.Operation to the user's operation handler method
https://github.com/temporalio/sdk-python/blob/nexusrpc-update/temporalio/nexus/_decorators.py#L120.
It seems to me that set_operation is an API that the library must expose, for this reason.
Their nexus caller uses get_operation in two situations, both in the situation where their caller invokes an operation by referring directly to the operation handler method (as opposed to the operation definition in the service definition):
- They need to obtain the operation name used to address the operation (i.e., perhaps the name override from the decorator): https://github.com/temporalio/sdk-python/blob/nexusrpc-update/temporalio/worker/_interceptor.py#L328
- They also use it to get the output type from the operation https://github.com/temporalio/sdk-python/blob/nexusrpc-update/temporalio/worker/_interceptor.py#L309-L310
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.
It seems to me that set_operation is an API that the library must expose, for this reason.
Hrmm, can end users' (and Temporal's) custom decorators not use the Nexus decorators themselves to mark this?
Their nexus caller uses get_operation in two situations, both in the situation where their caller invokes an operation by referring directly to the operation handler method (as opposed to the operation definition in the service definition)
Hrmm, arguably you should be able to obtain the service definition from the parent of the operation handler method in use. As a user that might want to write something that accepts either an operation contract or an operation handler, can I get the service definition that is on if I need/want it? Can Temporal do the same? Or maybe there's a static call on OperationDefinition to obtain just the operation if they don't care about which service it is on?
Also, why might a user want the nexusrpc.Operation (sugar for the definition) instead of the definition?
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 these are good questions. Let's merge this as-is since it's forward progress and is ntot changing the public API?
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.
Can we add it to your list so we make sure we don't forget about it? Having these get/set functions as public API at the top-level Nexus module is a bit surprising (not to mention they seem to be the only non-decorator module functions we have in public Nexus API).
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.
Added to list
4cd141d to
32318d5
Compare
79c228f to
562a2fd
Compare
32318d5 to
02397dd
Compare
562a2fd to
36da5d3
Compare
02397dd to
cb4777e
Compare
36da5d3 to
9db6a66
Compare
AI: This commit should have tag name type-assertions and should be force-pushed to a branch of that name as necessary.
AI: This commit should have tag name dataclass-transform and should be force-pushed to a branch of that name as necessary.
These are only required if the service handler does not specify an service definition. In that case, there will be an error when attempting to sythesize a valid OperationDefinition for the operation, since input and output types are non-nullable on OperationDefinition. AI: This commit should have tag name operation-definition and should be force-pushed to a branch of that name as necessary.
cb4777e to
9c06a2d
Compare
9db6a66 to
b6a3d13
Compare
This is PR 4/5 in a stack.
Introduces
nexusrpc.OperationDefinitionwith non-nullable fields. This is the internal counterpart of the user-facing syntactic sugarnexusrpc.Operation.It also performs a number of variable renames to avoid confusion between the two classes. This PR is pure refactoring without user-facing consequences.