airflow icon indicating copy to clipboard operation
airflow copied to clipboard

dag.owner_links does not validate owner/link length against the 500-char dag_owner_attributes columns; fails later at DB write time

Open rmfrall opened this issue 5 days ago • 1 comments

Apache Airflow version

main (3.5.0.dev)

What happened?

DAG(owner_links=...) only validates the URL format of each link (_validate_owner_links in task-sdk/src/airflow/sdk/definitions/dag.py), but neither the owner names nor the link values are checked against the 500-character limit of the dag_owner_attributes columns (DagOwnerAttributes in airflow-core/src/airflow/models/dag.py, owner and link are both String(500)).

A DAG author can pass a very long owner name or link: DAG authoring and parsing succeed, but when the dag processor writes owner attributes (_update_dag_owner_links in airflow-core/src/airflow/dag_processing/collection.py → DagModel.dag_owner_links.extend(...)), PostgreSQL fails with a raw database error (value too long for type character varying(500)), far removed from the DAG file that caused it. On SQLite (common dev setup) the value is silently accepted, hiding the problem until it reaches a length-enforcing DB.

What you think should happen instead?

Validation at the boundary, consistent with how the same module handles tag lengths (_validate_tags with TAG_MAX_LEN):

  • raise a clear ValueError at DAG creation time when an owner name or a link exceeds the column length, naming the offending entry and its actual length;
  • derive the limit from a shared constant instead of hard-coding the schema.

How to reproduce

from airflow.sdk import DAG

# no error at authoring time:
dag = DAG(
    dag_id="demo",
    schedule=None,
    owner_links={"o" * 600: "https://example.com"},  # owner far beyond 500 chars
)
# ...later, the dag-processor fails at DB write with a raw "value too long" error (postgres)

PostgreSQL evidence

Verified against PostgreSQL 16 with a table created from the actual migration DDL (dag_owner_attributes: owner varchar(500), link varchar(500)):

-- 500-char owner + 500-char link: accepted
INSERT INTO dag_owner_attributes (dag_id, owner, link)
VALUES ('demo-owner-len', repeat('o', 500), 'https://example.com/' || repeat('p', 480));
INSERT 0 1

-- 600-char owner (accepted by DAG() validation, fails at DB write):
INSERT INTO dag_owner_attributes (dag_id, owner, link)
VALUES ('demo-owner-len', repeat('o', 600), 'https://example.com');
ERROR:  value too long for type character varying(500)

-- 600-char link:
INSERT INTO dag_owner_attributes (dag_id, owner, link)
VALUES ('demo-owner-len', 'team', 'https://example.com/' || repeat('p', 600));
ERROR:  value too long for type character varying(500)

Operating System

any

Deployment

Apache Airflow (dag-processor + PostgreSQL)

Anything else?

Related precedents for the same class of "error surfaces too late" problems:

  • #55693 (per-tag 100-char limit, error message does not identify the offending tag)
  • #68382 (connection port range validated at use time instead of authoring time)

The public REST API datamodel for owner_links (core_api/datamodels/dags.py) also declares dict[str, str] without length constraints, so the API path has the same gap.

rmfrall avatar Nov 27 '26 12:11 rmfrall

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.

boring-cyborg[bot] avatar Nov 27 '26 12:11 boring-cyborg[bot]