You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2023/09/11 09:53:10 UTC
[GitHub] [airflow] uranusjr commented on a diff in pull request #34126: New 'clear_number' attribute for dag_run to track the number of times it has been cleared
uranusjr commented on code in PR #34126:
URL: https://github.com/apache/airflow/pull/34126#discussion_r1321291408
##########
airflow/models/dagrun.py:
##########
@@ -140,6 +140,7 @@ class DagRun(Base, LoggingMixin):
default=select(func.max(LogTemplate.__table__.c.id)),
)
updated_at = Column(UtcDateTime, default=timezone.utcnow, onupdate=timezone.utcnow)
+ clear_number = Column(Integer, default=0)
Review Comment:
```suggestion
clear_number = Column(Integer, default=0, nullable=False)
```
to match the migration?
##########
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py:
##########
@@ -0,0 +1,55 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""add new field 'clear_number' to dagrun
+
+Revision ID: 375a816bbbf4
+Revises: 405de8318b3a
+Create Date: 2023-09-05 19:27:30.531558
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+
+# revision identifiers, used by Alembic.
+revision = "375a816bbbf4"
+down_revision = "405de8318b3a"
+branch_labels = None
+depends_on = None
+airflow_version = "2.8.0"
+
+
+def upgrade():
+ """Apply add cleared column to dagrun"""
+ with op.batch_alter_table("dag_run") as batch_op:
+ batch_op.add_column(
+ sa.Column(
+ "clear_number",
+ sa.Integer,
+ default=0,
+ nullable=False,
+ )
Review Comment:
I also wonder if we want to add a constraint on this to ensure the value is not negative. Or if not, maybe we should change the `== 0` check to `< 1` instead. A bit paranoid probably, but it’s mostly free safety so why not.
##########
airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py:
##########
@@ -0,0 +1,55 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""add new field 'clear_number' to dagrun
+
+Revision ID: 375a816bbbf4
+Revises: 405de8318b3a
+Create Date: 2023-09-05 19:27:30.531558
+
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+
+# revision identifiers, used by Alembic.
+revision = "375a816bbbf4"
+down_revision = "405de8318b3a"
+branch_labels = None
+depends_on = None
+airflow_version = "2.8.0"
+
+
+def upgrade():
+ """Apply add cleared column to dagrun"""
+ with op.batch_alter_table("dag_run") as batch_op:
+ batch_op.add_column(
+ sa.Column(
+ "clear_number",
+ sa.Integer,
+ default=0,
+ nullable=False,
+ )
Review Comment:
I also wonder if we want to add a constraint on this to ensure the value is not negative. Or if not, maybe we should change the `== 0` check to `< 1` instead. A bit paranoid probably, but it’s mostly free safety so why not.
##########
airflow/models/dagrun.py:
##########
@@ -210,6 +211,7 @@ def __init__(
dag_hash: str | None = None,
creating_job_id: int | None = None,
data_interval: tuple[datetime, datetime] | None = None,
+ clear_number: int = 0,
Review Comment:
Is this argument used anywhere? I wonder if we should just have `self.clear_number = 0` always and rely on in-place modification instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org