ashb commented on code in PR #69757:
URL: https://github.com/apache/airflow/pull/69757#discussion_r3728052497


##########
airflow-core/src/airflow/api_fastapi/execution_api/datamodels/task_arg_binding.py:
##########
@@ -0,0 +1,93 @@
+# 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.
+"""
+Positional-argument binding spec for stub (foreign-runtime) tasks.
+
+Captured at parse time from the ``@task.stub`` TaskFlow call, stored in the 
serialized
+Dag, and delivered to the lang-SDK runtime via ``TIRunContext.arg_bindings``.
+"""
+
+from __future__ import annotations
+
+from functools import cache
+from typing import Annotated, Literal
+
+from pydantic import Field, JsonValue, TypeAdapter
+from typing_extensions import TypeAliasType
+
+from airflow.api_fastapi.core_api.base import BaseModel
+
+# A named, titled alias (like TaskArgBinding below) kept as free-form JSON 
rather than a
+# typed model, so unknown JSON-schema keywords survive re-serialization along 
the way.
+ArgValueSchema = TypeAliasType(
+    "ArgValueSchema", Annotated[dict[str, JsonValue], 
Field(title="ArgValueSchema")]
+)
+"""JSON-schema fragment constraining the value a stub-task argument binds to; 
generated
+by pydantic from the stub annotation, carried verbatim, unknown keywords 
ignored."""
+
+
+class _ArgBindingBase(BaseModel):
+    """Fields every :class:`TaskArgBinding` variant carries, regardless of 
``kind``."""
+
+    name: str
+    """The stub function's parameter name this binding fills, in declaration 
order."""
+
+    value_schema: ArgValueSchema | None = None
+    """Schema fragment from the stub function's annotation; omitted when 
unconstrained."""
+
+
+class XComArgBinding(_ArgBindingBase):
+    """One positional stub-task argument pulled from an upstream task's 
XCom."""
+
+    # No default: it would drop ``kind`` from ``required``, and the generated 
task-sdk
+    # client then types it ``Literal | None``, invalid as a tagged-union 
discriminator.
+    kind: Literal["xcom"]

Review Comment:
   Elsewhere we do this:
   
   ```python
       state: Annotated[
           Literal[TIState.RUNNING],
           # Specify a default in the schema, but not in code.
           WithJsonSchema({"type": "string", "enum": [TIState.RUNNING], 
"default": TIState.RUNNING}),
       ]
   ```
   
   It might be worth seeing if we can do the same thing here to apply a default 
too?
   
   Or this approach from ExecuteTask workload:
   
   ```python
       type: Literal["ExecuteTask"] = Field(init=False, default="ExecuteTask")
   ```



-- 
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]

Reply via email to