# Troubleshooting

> Common Apache Airflow problems on Kubernetes, covering task logs in Azure or S3, API workers, DAG syntax checks and LDAP logins after a major upgrade.

## Azure Blob Storage Logging

Azure’s `ADLS` can be used to store Airflow task logs.

Assume a regular storage container in Azures ADLS backend: this can be accessed with either the `adls[s]` or `wasb` connector using the [Azure Data Lake Storage Gen2 Connection](https://airflow.apache.org/docs/apache-airflow-providers-microsoft-azure/stable/connections/adls_v2.html) or the [Microsoft Azure Blob Storage Connection](https://airflow.apache.org/docs/apache-airflow-providers-microsoft-azure/stable/connections/wasb.html) respectively.

If `ADLS` is used as a task log backend it must be accessed via `wasb` and thus the configuration in the environment should look like:

```yaml
  webservers:
    envOverrides: &logging_overrides
      AIRFLOW__AZURE_REMOTE_LOGGING__REMOTE_WASB_LOG_CONTAINER: "<container-name>" (1)
      AIRFLOW__LOGGING__REMOTE_BASE_LOG_FOLDER: "wasb-<folder-name>" (2)
      AIRFLOW__LOGGING__REMOTE_LOGGING: "True"
      AIRFLOW__LOGGING__REMOTE_LOG_CONN_ID: "<connection-name>" (3)
  triggerers:
    envOverrides: *logging_overrides
  kubernetesExecutors:
    envOverrides: *logging_overrides
  schedulers:
    envOverrides: *logging_overrides
```

(1) This env var is only used for wasb connections.
(2) Note that the <container-name> is **not** referenced.
(3) This connection can be defined in the AirflowUI or declared as an environment variable.

Due to this open [issue](https://github.com/apache/airflow/issues/58946) with Airflow, it’s recommended to use `wasb-<folder-name>` rather then `wasb://<folder-name>` as using the latter option would assume the target location looks like this:

```text
<container-name>
  └── wasb:/
      └── tasklogs/
          └── dag_id=...
```

However the workaround will result in

```text
<container-name>
  └── wasb-tasklogs/
      └── dag_id=...
```

The `Azure Blob Storage Connection` will offer the optional field `Host` which should have a value looking like this:

```text
https://<storage-account-name>.blob.core.windows.net
```

## S3 Logging: An error occurred (411) when calling the PutObject operation: Length Required

If Airflow is trying to access S3 (e.g. for remote task logging) and throws the following error

```text
{s3_task_handler.py:190} ERROR - Could not write logs to s3://***/***-task-logs/dag_id=test/run_id=manual__2025-05-22T08:14:17.917519+00:00/task_id=extract/attempt=1.log
Traceback (most recent call last):
[..]
botocore.exceptions.ClientError: An error occurred (411) when calling the PutObject operation: Length Required
```

then this is an indication that your S3 store doesn’t support the new AWS S3 checksums. Ideally you should upgrade your S3 store to a more recent version that supports the new checksums (if there is any). If this is not possible, you can work around this by setting the following env vars

```yaml
webservers: # Also add to other roles!
  envOverrides:
    AWS_REQUEST_CHECKSUM_CALCULATION: when_required
    AWS_RESPONSE_CHECKSUM_VALIDATION: when_required
```

See e.g. [this MinIO issue](https://github.com/minio/minio/issues/20845) for details.

## Setting API Workers

In Airflow the webserver (called the API Server in Airflow 3.x+) can use multiple workers. This is determined by the environment variable `AIRFLOW__API__WORKERS` and is set by default to `1`. For most cases this should work without problem, but if you run into performance issues and would like to add more workers, you can either modulate multiple worker processes at the level of webserver (keeping the default value for each instance):

```yaml
webservers:
  roleGroups:
    default:
      replicas: 2 # add a replica (with the default number of workers)
```

or change the environment variable using `envOverrides`:

```yaml
webservers:
  envOverrides:
    AIRFLOW__API__WORKERS: "4" # something other than the default
```

> **Tip:** Our strong recommendation is to increase the webserver replicas, with each webserver running a single worker, as this removes the risk of running into timeouts or memory issues.

## Checking DAG syntax (Upgrading to Airflow 3.x+)

DAG files that ran under Airflow 2.x may need to be adjusted to be compatible with Airflow 3.x+. The [documentation](https://airflow.apache.org/docs/apache-airflow/stable/best-practices.html#installing-and-using-ruff) shows how this can be done with the Python `ruff` tool. For example, the following DAG was compatible with Airflow 2.x:

```python
import pendulum
from airflow import DAG
from airflow.decorators import task
from airflow.operators.bash import BashOperator

@task(task_id="run_this")
def run_this_func(dag_run=None):
    """
    Print the payload "message" passed to the DagRun conf attribute.

    :param dag_run: The DagRun object
    :type dag_run: DagRun
    """
    print(f"Remotely received value of {dag_run.conf.get('message')} for key=message")

with DAG(
    dag_id="example_trigger_target_dag",
    start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
    catchup=False,
    schedule_interval=None,
    tags=['example'],
) as dag:
    run_this = run_this_func()

    bash_task = BashOperator(
        task_id="bash_task",
        bash_command='echo "Here is the message: $message"',
        env={'message': '{% raw %}{{ dag_run.conf.get("message") }}{% endraw %}'},
    )
```

Assume this DAG lies in the `dags` folder in the current directory. Testing this with `ruff` indicates one incompatibility with Airflow 3.x and one deprecated operator:

```bash
$ ruff check dags/ --select AIR3 --preview
dags/dag.py:6:2: AIR311 `airflow.decorators.task` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
  |
4 | from airflow.operators.bash import BashOperator
5 |
6 | @task(task_id="run_this")
  |  ^^^^ AIR311
7 | def run_this_func(dag_run=None):
8 |     """
  |
  = help: Use `airflow.sdk.task` instead

dags/dag.py:20:5: AIR301 [*] `schedule_interval` is removed in Airflow 3.0
   |
18 |     start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
19 |     catchup=False,
20 |     schedule_interval=None,
   |     ^^^^^^^^^^^^^^^^^ AIR301
21 |     tags=['example'],
22 | ) as dag:
   |
   = help: Use `schedule` instead

dags/dag.py:25:17: AIR312 `airflow.operators.bash.BashOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
   |
23 |     run_this = run_this_func()
24 |
25 |     bash_task = BashOperator(
   |                 ^^^^^^^^^^^^ AIR312
26 |         task_id="bash_task",
27 |         bash_command='echo "Here is the message: $message"',
   |
   = help: Install `apache-airflow-providers-standard>=0.0.1` and use `airflow.providers.standard.operators.bash.BashOperator` instead.

Found 3 errors.
[*] 1 fixable with the `--fix` option.
```

## LDAP login fails after upgrading to Airflow 3.x+ ("No LDAP object found")

After upgrading from Airflow 2 to Airflow 3, LDAP logins that previously worked may start failing. The API server logs a line like the following (note, it is logged at `info` level, not as an error, so filtering for errors will miss it):

```text
[info     ] No LDAP object found for: john.smith [airflow.providers.fab.auth_manager.security_manager.override] loc=override.py:1840
```

This can happen if you were side-loading your own `webserver_config.py` and pointing Airflow at it with the `AIRFLOW__WEBSERVER__CONFIG_FILE` environment variable (for example via `envOverrides` plus a mounted ConfigMap).

In Airflow 3 the setting that selects the FAB config file [moved into the FAB provider](https://github.com/apache/airflow/pull/50774): it is now read from `AIRFLOW__FAB__CONFIG_FILE` (config key `[fab] config_file`, default `$AIRFLOW_HOME/webserver_config.py`) and the old `AIRFLOW__WEBSERVER__CONFIG_FILE` is no longer read. The operator generates `webserver_config.py` from your [AuthenticationClass](https://docs.stackable.tech/home/stable/airflow/usage-guide/security/index.md) and places it at that default path, so on Airflow 3 your custom file is silently ignored and the operator-generated LDAP configuration is used instead. If that generated configuration does not match your directory (for example a wrong `ldapFieldNames.uid`), the LDAP search returns no user and login fails.

Mounting your own file and overriding the config-file location was never a supported setup and now breaks silently. To customize `webserver_config.py`, use `configOverrides` together with `FILE_HEADER` and `FILE_FOOTER` as described in [Configuration & Environment Overrides](https://docs.stackable.tech/home/stable/airflow/usage-guide/overrides/index.md). All LDAP connection details themselves belong in the [AuthenticationClass](https://docs.stackable.tech/home/stable/airflow/usage-guide/security/index.md).

> **Tip:** You can confirm which file Airflow actually loads by running `airflow config get-value fab config_file` inside the pod.

## PYTHONPATH with custom DAGs folder using python modules

When a custom DAG folder (e.g. `/dags`) is defined with `envOverrides` and some DAGs contain a python module structure, then the variable `PYTHONPATH` should be explicitly defined to contain both this folder and the log config location that is set by the operator. This setting is done automatically by the operator when the default DAGs folder or gitsync are used, but is not done when this is set by the user directly.

```yaml
    envOverrides: &envOverrides
      AIRFLOW__CORE__DAGS_FOLDER: "/dags"
      PYTHONPATH: "/stackable/app/log_config:/dags"
```

> **Note:** Generally speaking it is [recommended](https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#configuration-reference) by Airflow to have the same config everywhere across all components.

## GitSync race condition

The operator runs a one-off `git-sync` process in an init container in every Pod, so the repository is guaranteed to be fully cloned before any Airflow process starts. A `git-sync` sidecar container then keeps the cloned repository up to date while the Pod is running. A race condition can still arise for content that is added to the repository **after** a Pod has started and is delivered by the sidecar: the long-running Python process started by the Airflow dag-processor has cached python submodules and a newly synced submodule may therefore not be found, even though it is already present on disk. This is indeterminate but can be avoided by adding the following lines to the top of each DAG file that references submodules:

```python
import importlib
import site

# invalidate import caches so that modules synced after process start are found
importlib.reload(site)
importlib.invalidate_caches()
```

These lines run whenever the DAG file is parsed by the dag-processor or re-parsed for task execution on workers, and add some overhead that should be minimal in comparison to parsing the DAG as a whole.

> **Note:** This workaround does not cover the triggerer: the triggerer does not parse DAG files, but imports trigger classes and callables directly at runtime, so code placed in a DAG file never runs in that process. If a deferred task references a module that was added to the repository after the triggerer Pod started and fails with `ModuleNotFoundError`, then restarting the triggerer may resolve this. This starts a fresh Python process with no stale import caches, and the init container guarantees the repository is fully synced before it starts.
