Is it allowed to run an activity inside a query?

Should an activity be allowed to run inside a query?

@Hrishikesh_Chappadi, you can not call an activity inside a query. If you do it, your code is gonna throw an error “Called from non workflow or workflow callback thread”

Queries are synchronous operations, they are not registered in the event history, they are directly delivered to the worker instead.

If I can ask, why do you need to do it?

Hi @antonio.perez thanks for the reply! I need to do some state validations through the query. Hence I need access to my entity DB via my temporal client.

@Hrishikesh_Chappadi

How is created the entity in DB?

I am asking because, if the entity is created from an activity, you could store the object in your workflow, and it will be available in your query method.

Then every update of that entity needs to flow through temporal.

I feel we should allow Temporal to account for people who want to use Temporal to choreograph instead of orchestrate.

You should be able to call any external API from your workflow query handler as long as it doesn’t mutate workflow state or generate workflow commands (such as scheduling an activity).
When we release synchronous update in 2023, that limitation will be lifted.

1 Like