kaxil commented on code in PR #70943:
URL: https://github.com/apache/airflow/pull/70943#discussion_r3704800360
##########
airflow-core/src/airflow/utils/yaml.py:
##########
@@ -68,6 +68,6 @@ def __getattr__(name):
if name == "FullLoader":
# Try to use CFullLoader by default
- getattr(yaml, "CFullLoader", yaml.FullLoader)
+ return getattr(yaml, "CFullLoader", yaml.FullLoader)
Review Comment:
`CFullLoader` isn't a subclass of `FullLoader` (MRO is `CParser,
FullConstructor, Resolver`), and `yaml.add_constructor(tag, fn)` only registers
on `Loader`/`FullLoader`/`UnsafeLoader`. So registering a tag through this same
wrapper and then loading with it goes from working to raising, not to silently
ignoring:
```python
from airflow.utils import yaml
yaml.add_constructor("!tag", lambda l, n: {"v": l.construct_scalar(n)})
yaml.load("a: !tag hi", Loader=yaml.FullLoader)
# before: {'a': {'v': 'hi'}}
# after: ConstructorError: could not determine a constructor for the tag
'!tag'
```
No in-tree caller reads `FullLoader` through these wrappers, but
`airflow.sdk.yaml` is re-exported into template macros, so `{{
macros.yaml.FullLoader }}` is reachable from DAG code. Deleting the branch
(leaving `FullLoader` as pyyaml's) is the zero-risk option, and the module
docstring does promise a drop-in `yaml`. Which way do we want it? Worth
updating the PR body either way, "does not see constructors" reads as a silent
no-op.
##########
airflow-core/tests/unit/utils/test_yaml.py:
##########
@@ -0,0 +1,28 @@
+# 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
+
+import yaml as pyyaml
+
+from airflow.utils import yaml
+
+
+def test_full_loader_prefers_the_c_implementation(monkeypatch):
+ c_full_loader = type("CFullLoader", (), {})
+ monkeypatch.setattr(pyyaml, "CFullLoader", c_full_loader, raising=False)
+
+ assert yaml.FullLoader is c_full_loader
Review Comment:
All three copies of this test only pin the libyaml-present branch. Every
PyYAML wheel on PyPI bundles libyaml, so CI never exercises the fallback, which
means `return yaml.CFullLoader` would pass here and `AttributeError` on a
source build. A `monkeypatch.delattr(pyyaml, "CFullLoader", raising=False)`
case asserting `yaml.FullLoader is pyyaml.FullLoader` closes that cheaply.
--
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]