apache / apache/airflow

LogTemplate table not seeded in custom schema causes TypeError when triggering DAG

Open
#47,300 12 comments 1 reaction 0 assignees View on GitHub
_eol_affected_version:2.10 area:db-migrations area:logging kind:bug
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 10h
Merged PRs (30d)
483

Description

### Apache Airflow version

Other Airflow 2 version (please specify below)

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

2.10.4

### What happened?

What happened:
When using a custom schema for the Airflow metadata database, the log_template table is not automatically seeded with default data. As a result, when triggering a DAG, Airflow attempts to set the log_template_id using the following code:

run.log_template_id = int(session.scalar(select(func.max(LogTemplate.__table__.c.id))))
Because the custom schema’s log_template table is empty, the query returns None, and attempting to convert None to an integer raises a TypeError:
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
In contrast, when using the default public schema, the table is seeded with default data, and this error does not occur.

### What you think should happen instead?

The log_template table should be seeded with default data even when using a custom schema—just as it is for the public schema. Alternatively, the code should handle an empty log_template table gracefully (for example, by defaulting to 0 when no rows exist).

### How to reproduce

Create a custom schema in your Airflow metadata database (e.g., my_custom_schema).
Update the Airflow configuration (in airflow.cfg or via the environment variable **sql_alchemy_schema = ${SQL_ALCHEMY_SCHEMA}**
to use your custom schema.

- Start Airflow.
- Run db migrate ( this will add permisssions and tables inside the schema)
- Trigger a DAG via the UI or API.
- Observe that the DAG trigger fails with the following error:
- TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
because the log_template table in the custom schema is empty.

![Image](https://github.com/user-attachments/assets/f9adee33-b737-4430-9931-754503ad64f8)

Image

### Operating System

docker container- aws ecs

### Versions of Apache Airflow Providers

2.10.4 ( docker image)

### Deployment

Other Docker-based deployment

### Deployment details

we used the offciail docker image from airflow and on top of that we run few commands and deploy it in aws ecs service

### Anything else?

_No response_

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!

### Code of Conduct

- [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

Contributor guide

Open the contributing guide

Research direction

Start with the `db migrate` entry point and inspect how the `log_template` table is seeded for the public and custom schemas. Reproduce the failure by triggering a DAG after migration, then verify that the custom-schema table contains default data or that an empty table is handled without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.