fat-catTW commented on code in PR #71214:
URL: https://github.com/apache/airflow/pull/71214#discussion_r4370936143


##########
airflow-core/src/airflow/migrations/versions/0150_3_5_0_add_dagrun_id_to_callback.py:
##########
@@ -0,0 +1,219 @@
+# 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 dagrun_id foreign key to callback.
+
+Revision ID: 0f4c9a2b8e1d
+Revises: c71065a1b14f
+Create Date: 2026-08-06 00:00:00.000000
+
+"""
+
+from __future__ import annotations
+
+import json
+
+import sqlalchemy as sa
+from alembic import context, op
+
+from airflow.configuration import conf
+from airflow.migrations.utils import disable_sqlite_fkeys
+
+# revision identifiers, used by Alembic.
+revision = "0f4c9a2b8e1d"
+down_revision = "c71065a1b14f"
+branch_labels = None
+depends_on = None
+airflow_version = "3.5.0"
+
+
+def _deserialize_data(data):
+    if isinstance(data, str):
+        try:
+            data = json.loads(data)
+        except json.JSONDecodeError:
+            return {}
+    return data.get("__var", data) if isinstance(data, dict) else {}
+
+
+def _extract_dagrun_id(data) -> int | None:
+    dagrun_id = _deserialize_data(data).get("dag_run_id")
+    if dagrun_id is None:
+        return None
+    try:
+        return int(dagrun_id)
+    except (TypeError, ValueError):
+        return None
+
+
+def _backfill_dagrun_id_from_deadline(conn, batch_size: int) -> None:

Review Comment:
   Based on the benchmark results, I think it is reasonable to backfill 
`callback.dagrun_id`.
   This is a one-time cost that normalizes existing callbacks to the 
database-managed relationship. It also lets us remove the read-side fallback to 
legacy `callback.data` instead of maintaining both representations.



-- 
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