uranusjr commented on code in PR #74084: URL: https://github.com/apache/airflow/pull/74084#discussion_r4241214989
########## task-sdk/src/airflow/sdk/importers/yaml_importer/parser.py: ########## @@ -0,0 +1,101 @@ +# 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. + +"""Parse a YAML/JSON DAG file into validated :class:`~.models.DagDocument` objects.""" + +from __future__ import annotations + +import collections.abc +import datetime +from typing import TYPE_CHECKING, Any + +import yaml +from pydantic import ValidationError + +from airflow.sdk.importers.yaml_importer import migrator +from airflow.sdk.importers.yaml_importer.models import DagDocument + +if TYPE_CHECKING: + from collections.abc import Hashable, Iterator + from typing import IO + + from yaml.nodes import MappingNode + + +class _UniqueKeySafeLoader(yaml.SafeLoader): + """ + A ``SafeLoader`` that rejects duplicate mapping keys. + + PyYAML keeps the last value for a repeated key, so a second ``tasks:`` block + or a second ``with:`` or ``needs:`` on a task would silently drop the first. + This can be a footgun for a hand-edited format, so we raise a + ``ConstructorError`` instead of silently shadowing. + """ + + def construct_mapping(self, node: MappingNode, deep: bool = False) -> dict[Hashable, Any]: + seen: set[Hashable] = set() + for key_node, _ in node.value: + key = self.construct_object(key_node, deep=deep) Review Comment: Now supported. -- 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]
