Skip to content

Conversation

@adrien-f
Copy link
Contributor

I've noticed that when executing a class activity, the type hinting was not taken into account. I've reflected this into the unit test with an additional assert.

This match the behavior of the docs where the usage is to pass the class type, not its instance:

result = await workflow.execute_activity_class(
    CallableClassActivity, to_add, start_to_close_timeout=timedelta(seconds=30)
)

Signed-off-by: Adrien Fillon [email protected]

What was changed

_type_hints_from_func was not taking into account when passed with a callable class

Why?

So we can properly execute class-based activities by passing the class instead of the instance

Checklist

  1. Closes N/A

  2. How was this tested: Unit testing

  1. Any docs updates needed? N/A

I've noticed that when executing a class activity,
the type hinting was not taken into account. I've
reflected this into the unit test with an additional
assert.

This match the behavior of the docs where the usage is
to pass the class type, not its instance:

```python
result = await workflow.execute_activity_class(
    CallableClassActivity, to_add, start_to_close_timeout=timedelta(seconds=30)
)
```

Signed-off-by: Adrien Fillon <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Aug 10, 2022

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cretz
Copy link
Member

cretz commented Aug 10, 2022

Thanks! To confirm, without your change here that test fails right? Will merge soon.

Also, if you can use methods instead of __call__ you might want to do that instead and use execute_activity_method. It can be clearer what is being called and will let you support multiple methods on the same class.

# Callable instance
call_func = getattr(type(func), "__call__", None)
# Class type or Callable instance
tmp_func = func if isinstance(func, type) else type(func)
Copy link
Member

Choose a reason for hiding this comment

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

Would have liked a better variable name than tmp_func but this is fine for now

@cretz cretz merged commit 8171049 into temporalio:main Aug 10, 2022
@adrien-f adrien-f deleted the activity-class-type branch August 10, 2022 14:16
@adrien-f
Copy link
Contributor Author

adrien-f commented Aug 10, 2022

Thanks! To confirm, without your change here that test fails right? Will merge soon.

Also, if you can use methods instead of __call__ you might want to do that instead and use execute_activity_method. It can be clearer what is being called and will let you support multiple methods on the same class.

To confirm, that both tests would fail, the workflow test was passing because of the conversion of the dict to the dataclass in the workflow return.

Oh, I wasn't aware of the execute_activity_method, it's clearer indeed 👍

Thanks for the quick merge!

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.

3 participants