-
Notifications
You must be signed in to change notification settings - Fork 477
Description
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:
- Create a new Go project that imports the genkit postgresql plugin.
- Attempt to instantiate a Postgres instance with a custom engine using only exported constructors/functions.
- There is no way to set the engine field from outside the package.
- 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
Projects
Status