ashb commented on code in PR #74084: URL: https://github.com/apache/airflow/pull/74084#discussion_r4182062714
########## scripts/ci/prek/dump_yaml_importer_schema.py: ########## Review Comment: Do we need two dump scripts, or are they similar enough it could be one script with an arg to change behaviour? (Not so easy to compare as I'm on mobile right now) ########## task-sdk/src/airflow/sdk/importers/yaml_importer/parser.py: ########## @@ -0,0 +1,72 @@ +# 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. + +The pydantic models (`.models`) are the schema; this module is the thin I/O + versioning +layer around them: it lazily streams each document of a multi-document YAML/JSON stream (a string or a +readable file object), +resolves its `$schema` version against the Cadwyn bundle (migrating an older-pinned document +up to head), validates it, and turns pydantic/YAML failures into a readable +:class:`YamlDagParseError` at the offending document. Parsing is lazy, so errors surface as +the iterator is consumed. It is pure (yaml + pydantic + cadwyn; no `airflow` import), so it is +unit-testable without a runtime. Review Comment: Last part: true but doesn't belong in doc string ########## task-sdk/src/airflow/sdk/importers/yaml_importer/schema.json: ########## @@ -0,0 +1,306 @@ +{ + "$defs": { + "CodeTask": { + "additionalProperties": true, + "description": "A task running custom code.\n\nThis should have ``run`` holding function arguments, and optionally\n``queue`` to route it.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "needs": { + "items": { + "type": "string" + }, + "title": "Needs", + "type": "array" + }, + "extends": { + "items": { + "type": "string" + }, + "title": "Extends", + "type": "array" + }, + "with": { + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/$defs/XComRef" + }, + { + "$ref": "#/$defs/TemplateRef" + }, + { + "$ref": "#/$defs/ConstRef" + }, + { + "$ref": "#/$defs/_Literal" + } + ] + }, + "title": "With", + "type": "object" + }, + "run": { + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/$defs/XComRef" + }, + { + "$ref": "#/$defs/TemplateRef" + }, + { + "$ref": "#/$defs/ConstRef" + }, + { + "$ref": "#/$defs/_Literal" + } + ] + }, + "title": "Run", + "type": "object" + } + }, + "required": [ + "id" + ], + "title": "CodeTask", + "type": "object" + }, + "ConstRef": { + "additionalProperties": false, + "description": "Force a literal; the value is taken verbatim.", + "properties": { + "$const": { + "title": "$Const" + } + }, + "required": [ + "$const" + ], + "title": "ConstRef", + "type": "object" + }, + "OperatorTask": { + "additionalProperties": true, + "description": "A ready-made operator.\n\nThis should have ``uses`` (import path) + ``with``.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "needs": { + "items": { + "type": "string" + }, + "title": "Needs", + "type": "array" + }, + "extends": { + "items": { + "type": "string" + }, + "title": "Extends", + "type": "array" + }, + "with": { + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/$defs/XComRef" + }, + { + "$ref": "#/$defs/TemplateRef" + }, + { + "$ref": "#/$defs/ConstRef" + }, + { + "$ref": "#/$defs/_Literal" + } + ] + }, + "title": "With", + "type": "object" + }, + "uses": { + "title": "Uses", + "type": "string" + } + }, + "required": [ + "id", + "uses" + ], + "title": "OperatorTask", + "type": "object" + }, + "TaskTemplate": { + "additionalProperties": true, + "description": "A reusable, partial task fragment merged into any task that ``extends`` it.\n\nThis holds arbitrary keys as-is. All validation is done on the merged task.", + "properties": {}, + "title": "TaskTemplate", + "type": "object" + }, + "TemplateRef": { + "additionalProperties": false, + "description": "A Jinja template.", + "properties": { + "$t": { + "title": "$T", + "type": "string" + } + }, + "required": [ + "$t" + ], + "title": "TemplateRef", + "type": "object" + }, + "TimetableSchedule": { + "additionalProperties": false, + "description": "A constructed timetable.", + "properties": { + "uses": { + "title": "Uses", + "type": "string" + }, + "with": { Review Comment: A timetable shouldn't allow xcom at the least ########## task-sdk/src/airflow/sdk/importers/yaml_importer/schema.json: ########## @@ -0,0 +1,306 @@ +{ + "$defs": { + "CodeTask": { + "additionalProperties": true, + "description": "A task running custom code.\n\nThis should have ``run`` holding function arguments, and optionally\n``queue`` to route it.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "needs": { + "items": { + "type": "string" + }, + "title": "Needs", + "type": "array" + }, + "extends": { + "items": { + "type": "string" + }, + "title": "Extends", + "type": "array" + }, + "with": { + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/$defs/XComRef" + }, + { + "$ref": "#/$defs/TemplateRef" + }, + { + "$ref": "#/$defs/ConstRef" + }, + { + "$ref": "#/$defs/_Literal" + } + ] + }, + "title": "With", + "type": "object" + }, + "run": { + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/$defs/XComRef" + }, + { + "$ref": "#/$defs/TemplateRef" + }, + { + "$ref": "#/$defs/ConstRef" + }, + { + "$ref": "#/$defs/_Literal" + } + ] + }, + "title": "Run", + "type": "object" + } + }, + "required": [ + "id" + ], + "title": "CodeTask", + "type": "object" + }, + "ConstRef": { + "additionalProperties": false, + "description": "Force a literal; the value is taken verbatim.", + "properties": { + "$const": { + "title": "$Const" + } + }, + "required": [ + "$const" + ], + "title": "ConstRef", + "type": "object" + }, + "OperatorTask": { + "additionalProperties": true, + "description": "A ready-made operator.\n\nThis should have ``uses`` (import path) + ``with``.", + "properties": { + "id": { + "title": "Id", + "type": "string" + }, + "needs": { + "items": { + "type": "string" + }, + "title": "Needs", + "type": "array" + }, + "extends": { + "items": { + "type": "string" + }, + "title": "Extends", + "type": "array" + }, + "with": { + "additionalProperties": { + "oneOf": [ + { + "$ref": "#/$defs/XComRef" + }, + { + "$ref": "#/$defs/TemplateRef" + }, + { + "$ref": "#/$defs/ConstRef" + }, + { + "$ref": "#/$defs/_Literal" + } + ] + }, + "title": "With", + "type": "object" + }, + "uses": { + "title": "Uses", + "type": "string" + } + }, + "required": [ + "id", + "uses" + ], + "title": "OperatorTask", + "type": "object" + }, + "TaskTemplate": { + "additionalProperties": true, + "description": "A reusable, partial task fragment merged into any task that ``extends`` it.\n\nThis holds arbitrary keys as-is. All validation is done on the merged task.", Review Comment: Nit: this is "leaking" rst in to the schema, and i imagine most things will show this as markdown -- 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]
