Skip to content

airflow tasks render CLI command error: sqlalchemy.orm.exc.DetachedInstanceError: Parent instance is not bound to a Session #63828

Description

@atul-astronomer

Apache Airflow version

main (development)

If "Other Airflow 3 version" selected, which one?

No response

What happened?

On running CLI command: airflow tasks render <dag_id> <task_id> <run_id>

Traceback (most recent call last):
  File "/usr/python/bin/airflow", line 10, in <module>
    sys.exit(main())
  File "/opt/airflow/airflow-core/src/airflow/__main__.py", line 55, in main
    args.func(args)
  File "/opt/airflow/airflow-core/src/airflow/cli/cli_config.py", line 49, in command
    return func(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/utils/cli.py", line 113, in wrapper
    return f(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/utils/cli.py", line 464, in _wrapper
    f(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/utils/providers_configuration_loader.py", line 54, in wrapped_function
    return func(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/cli/commands/task_command.py", line 477, in task_render
    context = _get_template_context(ti, task)
  File "/opt/airflow/airflow-core/src/airflow/cli/commands/task_command.py", line 249, in _get_template_context
    dag_run=DagRun.model_validate(ti.dag_run, from_attributes=True),
  File "/usr/python/lib/python3.10/site-packages/pydantic/main.py", line 716, in model_validate
    return cls.__pydantic_validator__.validate_python(
  File "/opt/airflow/airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py", line 335, in extract_dag_run_note
    values = {
  File "/opt/airflow/airflow-core/src/airflow/api_fastapi/execution_api/datamodels/taskinstance.py", line 336, in <dictcomp>
    field_name: getattr(data, field_name, None)
  File "/usr/python/lib/python3.10/site-packages/sqlalchemy/orm/attributes.py", line 569, in __get__
    return self.impl.get(state, dict_)  # type: ignore[no-any-return]
  File "/usr/python/lib/python3.10/site-packages/sqlalchemy/orm/attributes.py", line 1096, in get
    value = self._fire_loader_callables(state, key, passive)
  File "/usr/python/lib/python3.10/site-packages/sqlalchemy/orm/attributes.py", line 1131, in _fire_loader_callables
    return self.callable_(state, passive)
  File "/usr/python/lib/python3.10/site-packages/sqlalchemy/orm/strategies.py", line 922, in _load_for_state
    raise orm_exc.DetachedInstanceError(
sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <DagRun at 0xffff5bf5b790> is not bound to a Session; lazy load operation of attribute 'consumed_asset_events' cannot proceed (Background on this error at: https://sqlalche.me/e/20/bhk3)

What you think should happen instead?

No response

How to reproduce

  1. Create a dagrun for any Dag.
  2. Run CLI command airflow tasks render <dag_id> <task_id> <run_id>

Operating System

Linux

Versions of Apache Airflow Providers

No response

Deployment

Other

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Labels

affected_version:3.2Use for reporting issues with 3.2area:CLIarea:corekind:bugThis is a clearly a bugpriority:highHigh priority bug that should be patched quickly but does not require immediate new release

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions