Skip to content

Fix Effect query instance binding#5772

Open
agustif wants to merge 1 commit into
drizzle-team:betafrom
agustif:codex/effect-v4-generator-bindings
Open

Fix Effect query instance binding#5772
agustif wants to merge 1 commit into
drizzle-team:betafrom
agustif:codex/effect-v4-generator-bindings

Conversation

@agustif
Copy link
Copy Markdown

@agustif agustif commented May 17, 2026

Summary

Fixes the Effect PostgreSQL adapter paths that were relying on Effect.gen({ self: this }, function*() { ... this ... }) to preserve the class instance.

In current Effect v4, the generator this is the adapter object passed to Effect.gen, not the Drizzle class instance. That made prepared query execution, cache wrapping, and transaction construction read the wrong receiver at runtime.

This patch closes over self explicitly before entering Effect.gen and uses that captured instance inside:

  • PgEffectPreparedQuery.execute
  • PgEffectPreparedQuery.queryWithCache
  • EffectPgSession.transaction

It also adds a regression test that instantiates PgEffectPreparedQuery directly and verifies execute() uses the prepared query instance correctly.

Validation

  • pnpm exec dprint fmt drizzle-orm/src/pg-core/effect/session.ts drizzle-orm/src/effect-postgres/session.ts drizzle-orm/tests/effect-session.test.ts
  • pnpm exec dprint check drizzle-orm/src/pg-core/effect/session.ts drizzle-orm/src/effect-postgres/session.ts drizzle-orm/tests/effect-session.test.ts
  • pnpm exec oxlint drizzle-orm/src/pg-core/effect/session.ts drizzle-orm/src/effect-postgres/session.ts drizzle-orm/tests/effect-session.test.ts --max-warnings=0
  • pnpm --dir drizzle-orm exec vitest run tests/effect-session.test.ts

I also hit this from a downstream Effect v4 app using drizzle-orm/effect-postgres; before this fix the adapter could fail by reading fields like query / cache / client from the wrong receiver inside Effect.gen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant