Copilot commented on code in PR #61077:
URL: https://github.com/apache/airflow/pull/61077#discussion_r3066473231
##########
airflow-core/tests/unit/cli/commands/test_dag_command.py:
##########
@@ -1070,3 +1074,29 @@ def
test_reserialize_should_support_multiple_bundle_name_arguments(self, configu
serialized_dag_ids =
set(session.execute(select(SerializedDagModel.dag_id)).scalars())
assert serialized_dag_ids == {"test_example_bash_operator",
"test_sensor"}
+
+ @conf_vars({("core", "load_examples"): "false"})
+ def test_reserialize_should_make_equal_hash_with_dag_processor(self,
configure_dag_bundles, session):
+ bundles = {"bundle_reserialize": TEST_DAGS_FOLDER /
"test_dag_reserialize.py"}
+ with configure_dag_bundles(bundles):
+ dag_command.dag_reserialize(
+ self.parser.parse_args(["dags", "reserialize",
"--bundle-name", "bundle_reserialize"])
+ )
Review Comment:
`bundles` points at `TEST_DAGS_FOLDER / \"test_dag_reserialize.py\"`, but
this PR adds the DAG file under
`airflow-core/tests/unit/dags/test_dag_reserialize.py`. Unless
`TEST_DAGS_FOLDER` specifically resolves to `tests/unit/dags`, this test will
fail to find the file. Fix by moving the DAG fixture into the folder behind
`TEST_DAGS_FOLDER` (commonly `tests/dags`) or updating the bundle path in the
test to the actual file location.
##########
airflow-core/tests/unit/dags/test_dag_reserialize.py:
##########
@@ -0,0 +1,36 @@
+# 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
Review Comment:
This file is named like a pytest test module (`test_*.py`) and is placed
under `tests/unit/...`, but it contains a DAG definition fixture (executed at
import time) rather than tests. Pytest will still collect/import it during unit
test discovery, which can introduce unintended side effects and overhead.
Consider relocating this DAG fixture into the repo’s test DAGs/fixtures
directory (e.g., `tests/dags/`) and keeping unit test directories reserved for
actual tests.
##########
airflow-core/tests/unit/cli/commands/test_dag_command.py:
##########
@@ -1070,3 +1074,29 @@ def
test_reserialize_should_support_multiple_bundle_name_arguments(self, configu
serialized_dag_ids =
set(session.execute(select(SerializedDagModel.dag_id)).scalars())
assert serialized_dag_ids == {"test_example_bash_operator",
"test_sensor"}
+
+ @conf_vars({("core", "load_examples"): "false"})
+ def test_reserialize_should_make_equal_hash_with_dag_processor(self,
configure_dag_bundles, session):
+ bundles = {"bundle_reserialize": TEST_DAGS_FOLDER /
"test_dag_reserialize.py"}
+ with configure_dag_bundles(bundles):
+ dag_command.dag_reserialize(
+ self.parser.parse_args(["dags", "reserialize",
"--bundle-name", "bundle_reserialize"])
+ )
+
+ dagbag = DagBag(bundles["bundle_reserialize"],
bundle_path=bundles["bundle_reserialize"])
+ dag_parsing_result = DagFileParsingResult(
+ fileloc=bundles["bundle_reserialize"].name,
+ serialized_dags=[
+ LazyDeserializedDAG(data=DagSerialization.to_dict(dag)) for
dag in dagbag.dags.values()
+ ],
+ )
+
+ frame = _ResponseFrame(id=0,
body=dag_parsing_result.model_dump()).as_bytes()
+ request_frame =
msgspec.msgpack.Decoder[_RequestFrame](_RequestFrame).decode(frame[4:])
+ dag_processor_parsing_result =
DagFileProcessorProcess.decoder.validate_python(request_frame.body)
Review Comment:
This test constructs a `_ResponseFrame` and then decodes it as a
`_RequestFrame`, and also relies on a hard-coded `frame[4:]` offset. Even if
this happens to work today, it’s brittle and tightly coupled to private
framing/layout details. Prefer decoding with the matching frame type (or using
an existing helper that parses frames) and avoid magic offsets; alternatively,
validate the `DagFileParsingResult` payload directly through the same
pydantic/msgspec model the processor expects without re-framing it into bytes.
--
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]