uranusjr commented on PR #68629:
URL: https://github.com/apache/airflow/pull/68629#issuecomment-4794955572
According to Claude:
The `defaults.gen.go` approach addresses inbound decoding only. The outbound
encoding problem we discussed is still present: `GetPreviousTI.MapIndex`
remains int with omitempty, so sending `GetPreviousTI{MapIndex: 0}` to the
supervisor will silently drop the 0, and the supervisor will apply its default
(-1), incorrectly treating a map_index=0 request as unmapped.
The minimal fix is to add a pass in `gen/main.go` that rewrites any struct
field in `models.gen.go` where:
- the Go type is a concrete integer (`int`), **and**
- the schema property has a non-zero default (i.e., `defaultLiteral` would
produce a seed for it)
...from `int` to `*int`, and strips `omitempty` from the tag (since with a
pointer, nil already means "absent" and `omitempty` would be redundant and
confusing).
With this type, the call site passes `&mapIndex` to get it encoded, or `nil`
to omit it. The supervisor receives the explicit 0 and treats it as index 0,
not unmapped.
`defaults.gen.go` would then also need to change:
`GetPreviousTI.DecodeMsgpack` would use a `*int` pre-seed, which means `&-1` as
the default pointer. The alias constructor becomes `alias{MapIndex:
intPtr(-1)}` (with a small helper, or inline with `new(int)` and assignment).
Or, since `*int` + absent key decodes to `nil`, the decode-side default for
`GetPreviousTI.MapIndex` is just nil — and the call site treats nil the same as
-1. That's actually the cleaner outcome: the Go SDK sends `nil` to mean
"unmapped" (which the supervisor interprets as its -1 default), and sends `&0`
to mean index 0. No decode-side seeding needed at all for that field.
The change to `gen/main.go` would sit inside `writeDefaults` (or a new
pre-pass before it): scan `structs[structName]` for `int`-typed fields whose
schema property has a non-zero default, emit an AST rewrite of `models.gen.go`
that changes the field type to `*int` and strips `,omitempty` from the tag.
That rewrite would be analogous to the dead-typedef stripping already done in
`parseModels`.
--
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]