ephraimbuddy commented on code in PR #71621:
URL: https://github.com/apache/airflow/pull/71621#discussion_r3854158076
##########
airflow-core/src/airflow/models/serialized_dag.py:
##########
@@ -346,15 +346,23 @@ class SerializedDagModel(Base):
load_op_links = True
__table_args__ = (Index("idx_serialized_dag_dag_id_created_at", dag_id,
created_at),)
- def __init__(self, dag: LazyDeserializedDAG) -> None:
+ def __init__(self, dag: LazyDeserializedDAG, *, _dag_hash: str | None =
None) -> None:
+ """
+ Build a serialized Dag row.
+
+ :param _dag_hash: hash of ``dag.data`` when the caller has already
computed it, used by
+ ``write_dag`` to avoid hashing the same data twice. Hashing
re-sorts and re-encodes
+ the whole structure, so it is worth skipping. It must describe
``dag.data`` as it
+ stands now — recompute it first if the data was mutated after
hashing, or change
+ detection on the next parse silently misbehaves.
+ """
self.dag_id = dag.dag_id
dag_data = dag.data
- self.dag_hash = SerializedDagModel.hash(dag_data)
-
- # partially ordered json data
- dag_data_json = json.dumps(dag_data, sort_keys=True).encode("utf-8")
+ self.dag_hash = SerializedDagModel.hash(dag_data) if _dag_hash is None
else _dag_hash
Review Comment:
Yeah, safe
--
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]