Skip to content

Patch support and random/UUID helpers #35

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 4 commits into from
Jun 3, 2022
Merged

Conversation

cretz
Copy link
Member

@cretz cretz commented Jun 2, 2022

What was changed

  • Added patched() and deprecate_patch() workflow functions impl'd similar to TS ones
  • Added random() workflow function that returns a seeded random for use by users
  • Added uuid4() workflow function that uses the random call
  • Tests

Checklist

  1. Closes Versioning/Patching #27

@cretz cretz marked this pull request as ready for review June 2, 2022 21:34
@cretz cretz requested a review from a team June 2, 2022 21:34
Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

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

Nice, not a lot of work. Good to be seeing payoff from using Core.

Comment on lines +454 to +455
path are done and will never be queried again. Therefore the old code path
is removed as well.
Copy link
Member

Choose a reason for hiding this comment

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

Not necessary for this PR, but probably makes sense to link to docs page explaining the patch lifecycle

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately that doesn't exist for Python yet. https://docs.temporal.io/typescript/patching will be perfect in Python form if/when it exists. I have opened #37 to track this.

Copy link
Member

Choose a reason for hiding this comment

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

It should probably be part of the app dev guide

def _apply_update_random_seed(
self, job: temporalio.bridge.proto.workflow_activation.UpdateRandomSeed
) -> None:
self._random = random.Random(job.randomness_seed)
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably reseed the current _random reference in case users keep a reference to it
(https://docs.python.org/3/library/random.html#random.seed)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, of course, duh. Fixing.

Returns:
A deterministically-seeded v4 UUID.
"""
return uuid.UUID(bytes=random().getrandbits(16 * 8).to_bytes(16, "big"), version=4)
Copy link
Member

Choose a reason for hiding this comment

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

This is so much better than what I had to do in TS to get random and uuid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Saw that. This could be even better if I was able to use Random.randbytes() as present in 3.9+.

I hesitated adding these APIs at all because I was hoping a sandbox could provide the random and uuid modules, but we might as well have these available now (and technically we still may offer a no-sandbox approach in the future).

Copy link
Member

Choose a reason for hiding this comment

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

If we do have sandbox in the future we'll probably reuse these random and uuid implementations

@cretz cretz merged commit 962a5e8 into temporalio:main Jun 3, 2022
@cretz cretz deleted the patching branch June 3, 2022 17:38
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.

Versioning/Patching
3 participants