Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Create commands after payload conversion #591

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

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

cretz
Copy link
Member

@cretz cretz commented Jul 23, 2024

What was changed

Before this change, the Python SDK added commands on the activation completion before payload conversion and then filled them out including with conversion. This meant that in cases where the payload converter caused a application error (or was caught), the command would be half created/filled-in and you'd get errors like "invalid TaskQueue on ScheduleActivityTaskCommand: missing task queue name".

Now, in multiple places, we do the payload conversion before command creation/addition which allows exceptions to occur before the command is added.

Checklist

  1. Closes [Bug] Exception in converter encoding doesn't propagate as expected #540
  2. Closes [Bug] Converting payloads and other exception-possible actions done after command creation #564

@cretz cretz requested a review from a team as a code owner July 23, 2024 15:11
Copy link
Contributor

@dandavison dandavison left a comment

Choose a reason for hiding this comment

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

LGTM!

)
command = self._add_command()
command.respond_to_query.query_id = job.query_id
command.respond_to_query.succeeded.response.CopyFrom(result_payloads[0])
Copy link
Contributor

@dandavison dandavison Jul 23, 2024

Choose a reason for hiding this comment

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

Non-blocking: in general my view is that try blocks should enclose as little as possible. it seems that these 3 lines could go after?

Copy link
Member Author

Choose a reason for hiding this comment

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

No because this needs to only be called on the success path, there is a failure path that does another thing, there is no need for any common code after the try

except Exception as err:
try:
command = self._add_command()
command.respond_to_query.query_id = job.query_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking: I assume these lines cannot raise an exception; I would put them outside the try.

Copy link
Member Author

Choose a reason for hiding this comment

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

They were outside of try in the previous code, but the purpose of this fix is to not invoke these until it's time to make the command because if you call this before an exception is raised, you'll have an unfinished command that was added

@cretz cretz merged commit a5b9661 into temporalio:main Aug 9, 2024
12 checks passed
@cretz cretz deleted the failable-before-command branch August 9, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants