Skip to content

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

Closed

Description

@arvindmunna

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

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

Activity

  1. added
    kind:bug
    needs-triage
    on Mar 3, 2025
  2. boring-cyborg commented on Mar 3, 2025

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  3. added
    area:db-migrations
    on Mar 3, 2025
  4. added
    _eol_affected_version:2.10
    and removed
    needs-triage
    on Mar 3, 2025
  5. amolsr commented on Mar 3, 2025

    @amolsr
    Contributor

    hi, please assign this issue to me.

  6. amolsr commented on Mar 3, 2025

    @amolsr
    Contributor
    Image

    If you are running airflow db migrate. this would automatically create 2 entries in the table as shown in image. If you can provide more info on the setup, I would be able to help you better.

  7. arvindmunna commented on Mar 4, 2025

    @arvindmunna
    Author

    Hi @amolsr

    This happened with AWS RDS Postgres db version 15, we launched a micro db in postgres and tried running the db migrate and It did created the tables and default entries under Public schema, but we need a custom schema, so we created the custom schema and modified the airflow.cfg file sql_alchemy_schema and then re ran the db migrate to my remote postgres, this time it created the tables and permissions but there is no default values created in LogTemplate_id table. So this throws error when we trigger the dag even the example dags will fail.

    Solution : we ran a sql query manually to add some data in that empty LogTemplate_id table and this fixed the error.

    Note : This might be running ok with local dB's please try with the same setup I have told.

  8. arvindmunna commented on Mar 5, 2025

    @arvindmunna
    Author

    Any update on this @amolsr

  9. amolsr commented on Mar 5, 2025

    @amolsr
    Contributor

    Please share the DB permission for the user you are using.

  10. arvindmunna commented on Mar 5, 2025

    @arvindmunna
    Author

    I might not have permission to share those creds for db.

  11. amolsr commented on Mar 5, 2025

    @amolsr
    Contributor

    I’m not referring to credentials but to db user permissions. I wanted to verify whether your db user has the necessary permissions to perform insert operations on the schema you created. In some cases, db users are granted permissions for DDL operations but not for DML operations.

  12. arvindmunna commented on Mar 5, 2025

    @arvindmunna
    Author

    we used the default user and the user was the owner of the schema and the user has all permissions over the schema.

  13. amolsr commented on Mar 6, 2025

    @amolsr
    Contributor

    Can you share your database logs file for looking further? It feels like i have incomplete information to actually debug on the issue.

  14. FranciscoRuiz04 commented on Nov 7, 2025

    @FranciscoRuiz04

    Maybe you already fixed your issue @arvindmunna but this could help somebody else with the same problem.
    I'm running Airflow 3.1.0 with PostgreSQL version 16 as backend. What I found is that when you execute airflow db migrate with a custom schema other than public, Airflow does indeed use the schema name defined in AIRFLOW__DATABASE__SQL_ALCHEMY_SCHEMA to create all the tables it needs. However, when it tries to seed up the log_template table Airflow does not take into account the schema defined; that is, uses the default search path (public schema) instead. So, one possible solution is passing explicitly the search path value inside the URI like this:
    AIRFLOW__DATABASE__SQL_ALCHEMY_CONN=postgresql+psychoph2:user:password@host:port/db?options=-csearch_path%3Dschema

  15. f-necas commented on Dec 3, 2025

    @f-necas

    @FranciscoRuiz04 you saved my life

  16. added
    affected_version:3.1
    on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    _eol_affected_version:2.10affected_version:3.1area:db-migrationsarea:loggingkind:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions