The when keyword is evaluated as a Jinja2 expression without needing delimiters. Writing when: {{ some_var }} produces a deprecation warning in older versions and, in current ansible-core, a template error or a condition that evaluates the string rather than the variable.
The correct form is when: some_var is defined and some_var. The same rule applies to changed_when, failed_when, until, and the assert module's that, all of which take bare expressions.
Related: when on a task that also has loop is evaluated once per item, with item in scope, not once for the whole loop. when on a block applies to every task in it, and when on a include_role or include_tasks applies to the include itself, whereas on import_role or import_tasks it is copied onto every imported task individually. That last distinction explains why a conditional import still evaluates variables that do not exist yet: the condition is attached to each task rather than gating the import, and static imports are processed at parse time so runtime facts are unavailable to them.