Skip to content

Api-server sqlalchemy.exc.ArgumentError caused by in-task code accessing context for runs without a logical_date #48503

Closed

Description

@TJaniF

Apache Airflow version

3.0.0

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

breeze current main

What happened?

This dag works fine in 2.10 and in 3.0 when the dag has a logical_date supplied on manual run:

from airflow.decorators import dag, task
from collections.abc import Mapping


def _print_dict(d, indent=0):
    text_output = ""
    for key, value in d.items():
        text_output += " " * indent + f"{key}: "
        if isinstance(value, Mapping):
            text_output += "\n"
            text_output += _print_dict(value, indent + 4)
        else:
            text_output += f"{value}\n"
    return text_output


@dag(schedule=None, catchup=False)
def context_full_test_dag():
    @task
    def print_context(**context):
        print("------ START PRINT CONTEXT ------")
        dict_repr = _print_dict(context)
        print("------ END PRINT CONTEXT ------")
        print(dict_repr)

        with open("/files/dags/a", "w") as f:
            f.write(dict_repr)

        keys = []
        for key in context.keys():
            keys.append(key)
        print("------ START PRINT KEYS ------")
        print(keys)
        print("------ END PRINT KEYS ------")

        import json
        with open(
            "/files/dags/a.json",
            "w",
        ) as f:
            json.dump(keys, f)


    print_context()


context_full_test_dag()

When the dag is run manually without supplying a logical date, the API server throws a sqlalchemy error (sorry for the screenshot, tmux vscode keybinding mess)

Image

The error leads to the scheduler loosing connection to the API server, and eventually the scheduler crashes. (The task gets stuck)

What you think should happen instead?

A task error, not an api-server error.
Not entirely sure what in the task is causing this.

How to reproduce

Run the above dag in 3.0 manually without supplying a logical date.

Operating System

MacOS

Versions of Apache Airflow Providers

None

Deployment

Other

Deployment details

breeze

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Mar 28, 2025
  2. self-assigned this
    on Mar 28, 2025
  3. added
    priority:critical
    on Mar 28, 2025
  4. 9 remaining items

  5. added this to the Airflow 3.0.0 milestone on Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:corekind:bugneeds-triagepriority:critical

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions