Skip to content

Commit

Permalink
Add constraint to ensure task map length >= 0 (#21115)
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Jan 26, 2022
1 parent dff536e commit 80f30ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

from alembic import op
from sqlalchemy import Column, ForeignKeyConstraint, Integer, text
from sqlalchemy import CheckConstraint, Column, ForeignKeyConstraint, Integer, text

from airflow.models.base import StringID
from airflow.utils.sqlalchemy import ExtendedJSON
Expand Down Expand Up @@ -75,6 +75,7 @@ def upgrade():
Column("map_index", Integer, primary_key=True),
Column("length", Integer, nullable=False),
Column("keys", ExtendedJSON, nullable=True),
CheckConstraint("length >= 0", name="task_map_length_not_negative"),
ForeignKeyConstraint(
["dag_id", "task_id", "run_id", "map_index"],
[
Expand Down
3 changes: 2 additions & 1 deletion airflow/models/taskmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import enum
from typing import TYPE_CHECKING, Any, Collection, List, Optional

from sqlalchemy import Column, ForeignKeyConstraint, Integer, String
from sqlalchemy import CheckConstraint, Column, ForeignKeyConstraint, Integer, String

from airflow.models.base import COLLATION_ARGS, ID_LEN, Base
from airflow.utils.sqlalchemy import ExtendedJSON
Expand Down Expand Up @@ -61,6 +61,7 @@ class TaskMap(Base):
keys = Column(ExtendedJSON, nullable=True)

__table_args__ = (
CheckConstraint(length >= 0, name="task_map_length_not_negative"),
ForeignKeyConstraint(
[dag_id, task_id, run_id, map_index],
[
Expand Down

0 comments on commit 80f30ee

Please sign in to comment.