Skip to content

[Go] Postgres plugin cannot be initialized by consumers due to unexported engine field #3546

@lukaszKielar

Description

@lukaszKielar

Describe the bug
The Postgres struct in the Go plugin for postgresql has an unexported engine field and no public constructor or setter, making it impossible for consumers to properly initialize and use the plugin outside the package. Attempting to use the plugin in a custom Go project requires workarounds (like reflection/unsafe), which are not recommended. This prevents straightforward integration and testing.

Full error messages:

  • panic("postgres.Init engine is nil")
  • Cannot assign to p.engine as it is unexported

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Go project that imports the genkit postgresql plugin.
  2. Attempt to instantiate a Postgres instance with a custom engine using only exported constructors/functions.
  3. There is no way to set the engine field from outside the package.
  4. Calling Init on a Postgres instance without an engine panics.

Sample code:

engine, err := postgresql.NewPostgresEngine(ctx, opts...)
if err != nil { /* handle */ }
p := &postgresql.Postgres{}
p.engine = engine // not possible, field is unexported
p.Init(ctx) // panics: "postgres.Init engine is nil"

Expected behavior
Consumers should be able to initialize a Postgres instance with a custom engine using only exported APIs (e.g., a public constructor or setter), without reflection or unsafe. The plugin should offer a function like NewWithEngine(engine *PostgresEngine) *Postgres or a public SetEngine method, so that initialization is possible from outside the package. Documentation should clarify the initialization flow.

Screenshots
N/A (not a UI bug)

Runtime (please complete the following information):

  • OS: MacOS
  • Version: 15.6.1

Go version

  • go version go1.24.0 darwin/arm64

Additional context
See also: https://github.com/firebase/genkit/blob/main/go/plugins/postgresql/genkit.go for the relevant code context.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions