Skip to content

[Go SDK] Fix generic registration of anonymous struct types - #40649

Open
Thanatos9404 wants to merge 1 commit into
apache:masterfrom
Thanatos9404:fix-21789-register-anonymous-struct
Open

Thanatos9404 wants to merge 1 commit into
apache:masterfrom
Thanatos9404:fix-21789-register-anonymous-struct

Conversation

@Thanatos9404

@Thanatos9404 Thanatos9404 commented Oct 18, 2026 •

Copy link
Copy Markdown

Fixes #21789

The generic registration functions (register.Function*, register.DoFn* and register.Combiner*) pass every struct type a function takes or returns to runtime.RegisterType, which panics for unnamed types. So a function with an anonymous struct parameter panicked in init() and couldn't use generic registration at all.

registerMethodTypes now adds a struct type to the runtime registry only when it has a type key, and still adds every struct type to the schema registry, which the worker needs to map a row back to the user's Go type. The change is in register.tmpl, and register.go was regenerated with go generate. An unnamed struct that can't be converted to a schema now fails in beam.Init, like a named one, instead of panicking earlier.

I also enabled the register.Function1x1(castFn) call in the BigQuery xlang integration test that was waiting on this. I only checked that its test binary now initialises.

Tests: three new tests register functions and a DoFn with anonymous struct parameters or return types. All three fail on master with the panic and pass with this change. CHANGES.md is updated under Bugfixes for 2.78.0.

@github-actions github-actions Bot added the go label Oct 18, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR resolves a panic during generic registration (register.Function*, register.DoFn*, register.Combiner*) when functions or methods accept or return anonymous struct types. By introducing registerStructType, unnamed structs are skipped for runtime.RegisterType (which requires a type key) while still being registered with schema.RegisterType so row schemas and nested named structs are properly mapped on workers.

🔍 General Feedback

  • The changes in register.tmpl and the regenerated register.go are clean, minimal, and accurately target the root cause (#21789).
  • Re-enabling register.Function1x1(castFn) in bigquery_test.go and the new unit tests in register_test.go thoroughly cover parameter, return, and DoFn registration paths.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @shunping for label go.
Backup reviewer: jrmccluskey (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.41%. Comparing base (a8d6afd) to head (7241c9b).
⚠️ Report is 35 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #40649       +/-   ##
===========================================
- Coverage   80.04%   56.41%   -23.64%     
===========================================
  Files         490      871      +381     
  Lines       82916   154091    +71175     
===========================================
+ Hits        66373    86923    +20550     
- Misses      16543    65314    +48771     
- Partials        0     1854     +1854     
Flag Coverage Δ
go 28.87% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Generic registration registers every struct type that a function or
method takes or returns, with both the runtime type registry and the
schema registry. runtime.RegisterType panics for unnamed types, so
generic registration could not be used for a function with an anonymous
struct parameter, and it stopped before the caller and struct wrappers
were set up.

registerMethodTypes now adds a struct type to the runtime type registry
only when it has a type key, and still adds every struct type to the
schema registry, which maps a row schema back to the user's Go type on
the worker. graphx already encodes types without a type key field by
field.

This also enables the castFn registration in the BigQuery integration
test that was waiting on this issue.

Fixes apache#21789
@Thanatos9404
Thanatos9404 force-pushed the fix-21789-register-anonymous-struct branch from 5786fd5 to 7241c9b Compare October 21, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Go SDK registration panics on anonymous structs.

1 participant