Variables in automation: when they are calculated

Consider these examples:

  - alias: xxxx
    id: yyyy

    trigger:
      ...

    condition:
      ...

    action:
      - variables:
          my_var: >-
            {{ ... }}
      ...

and

  - alias: xxxx
    id: yyyy

    variables:
      my_var: >-
        {{ ... }}

    trigger:
      ...

    condition:
      ...

    action:
      ...

When these variables are calculated?
Is that correct:
– case 1: after checking “condition” if it is “true” and before executing the 1st action;
– case 2: after “triggered” before checking “condition”
?

In some automation I am using “case 1” and keep getting errors on reloading templates - although I tried to specify “condition” to trap these “temporary errors”.