Fix Effect query instance binding#5772
Open
agustif wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
thisis the adapter object passed toEffect.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
selfexplicitly before enteringEffect.genand uses that captured instance inside:PgEffectPreparedQuery.executePgEffectPreparedQuery.queryWithCacheEffectPgSession.transactionIt also adds a regression test that instantiates
PgEffectPreparedQuerydirectly and verifiesexecute()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.tspnpm exec dprint check drizzle-orm/src/pg-core/effect/session.ts drizzle-orm/src/effect-postgres/session.ts drizzle-orm/tests/effect-session.test.tspnpm 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=0pnpm --dir drizzle-orm exec vitest run tests/effect-session.test.tsI also hit this from a downstream Effect v4 app using
drizzle-orm/effect-postgres; before this fix the adapter could fail by reading fields likequery/cache/clientfrom the wrong receiver insideEffect.gen.