henry3260 opened a new pull request, #75602:
URL: https://github.com/apache/airflow/pull/75602

   `actx.DagRun()` now carries the conf the Dag run was triggered with, and 
reads it into a struct with typed fields.
   
   ```go
   type etlConf struct {
       TargetTable string
       Limit       int
       Since       time.Time
   }
   
   func load(actx airflow.Context) error {
       etl := etlConf{Limit: 100}
       if err := actx.DagRun().UnmarshalConf(&etl); err != nil {
           return err
       }
       ...
   }
   ```
   
   For a run triggered with `{"target_table": "sales", "since": 
"2024-01-31T00:00:00Z"}`, `etl.TargetTable` is `"sales"`, `etl.Since` is that 
date, and `etl.Limit` stays `100`.
   
   - The supervisor already sends the conf with the task's startup details, but 
the runtime dropped it on the way to the task, so a Go task could not read what 
its run was triggered with while a Python or a Java task can. `sdk.DagRun.Conf` 
is the conf as a `map[string]any`, and is nil for a run triggered without one.
   - Reading that map costs an assertion per key, and an integer has no single 
type to assert, because the wire picks its width from the value. 
`UnmarshalConf` leaves the types to the task author instead.
   - A key reaches the field whose name folds to the same token once case and 
underscores are ignored, which is how a TaskFlow argument already reaches its 
field, so `target_table` reaches `TargetTable`. A `json:` tag renames the field 
and matches the same way. Objects nested in the conf follow the same rule, 
including objects in slices and objects that are map values; the keys of a map 
field stay as written.
   - Keys that match no field are ignored, because other tasks in the run may 
read them. A field with no matching key keeps the value the struct already 
holds, so defaults are set before the call.
   - It returns an error when a value does not fit the type of its field, when 
two keys match one field and neither names it exactly, or when two fields of 
the struct differ only in case or underscores.
   
   related: #74674 — that PR exposes `Conf` together with `RunType` and 
`RunAfter`. The first commit here overlaps it, and I will drop that commit and 
rebase on it if it lands first. The typed binding is the part neither it nor 
the Java SDK's #75542 covers.
   
   The Java SDK is getting the same feature in #75542, and the TS SDK the conf 
itself in #75563. The matching rules here follow #75542 so that a conf key 
reaches the same field in every SDK.
   
   Verified in `go-sdk/`: `go test ./...`, `go test -race ./...`, `go vet 
./...`, the prek pre-commit and manual stages, and `breeze build-docs 
apache-airflow`. `TestTriggerDagRunRejectsAnInvalidSpec` fails on my machine 
with and without this change, because a Go 1.27 toolchain prints a different 
`encoding/json` error string than the repository's Go 1.25 target; it is 
unrelated to this PR.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Opus 5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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