amoghrajesh commented on code in PR #65759:
URL: https://github.com/apache/airflow/pull/65759#discussion_r3146183947


##########
airflow-core/src/airflow/state/__init__.py:
##########
@@ -0,0 +1,42 @@
+#
+# 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.
+from __future__ import annotations
+
+from airflow._shared.state import (
+    AssetScope as AssetScope,
+    BaseStateBackend as BaseStateBackend,
+    StateScope as StateScope,
+    TaskScope as TaskScope,
+)
+
+_DEFAULT_BACKEND = "airflow.state.metastore.MetastoreStateBackend"

Review Comment:
   Handled in [handle silent failure on 
resolve_state_backend](https://github.com/apache/airflow/pull/65759/commits/1d428fee7b1eac2f919999be3f1abf48aae9774c)



##########
airflow-core/src/airflow/models/task_state.py:
##########
@@ -0,0 +1,61 @@
+#
+# 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.
+from __future__ import annotations
+
+from datetime import datetime
+
+from sqlalchemy import ForeignKeyConstraint, Index, Integer, 
PrimaryKeyConstraint, String, Text
+from sqlalchemy.orm import Mapped, mapped_column
+
+from airflow._shared.timezones import timezone
+from airflow.models.base import COLLATION_ARGS, ID_LEN, Base
+from airflow.utils.sqlalchemy import UtcDateTime
+
+
+class TaskStateModel(Base):
+    """
+    Persists key/value state for a task within a single DAG run.
+
+    Scoped to (dag_run_id, task_id, map_index). Retries of the same task share
+    the same rows — that is the point. Different DAG runs have different 
dag_run_id
+    values so they get independent namespaces automatically.
+    """
+
+    __tablename__ = "task_state"
+
+    dag_run_id: Mapped[int] = mapped_column(Integer, nullable=False, 
primary_key=True)
+    task_id: Mapped[str] = mapped_column(String(ID_LEN, **COLLATION_ARGS), 
nullable=False, primary_key=True)
+    map_index: Mapped[int] = mapped_column(Integer, primary_key=True, 
nullable=False, server_default="-1")
+    key: Mapped[str] = mapped_column(String(512, **COLLATION_ARGS), 
nullable=False, primary_key=True)
+
+    dag_id: Mapped[str] = mapped_column(String(ID_LEN, **COLLATION_ARGS), 
nullable=False)
+    run_id: Mapped[str] = mapped_column(String(ID_LEN, **COLLATION_ARGS), 
nullable=False)
+
+    value: Mapped[str] = mapped_column(Text, nullable=False)

Review Comment:
   Wow nice catch. It would be a bummer for Mysql with this limit, I attempted 
to fix it for both task_state.value and asset_state.value by using 
`Text().with_variant(MEDIUMTEXT, "mysql")`, same pattern as `Variable._val` 
instead of documenting it and making it harder to use. WDYT?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to