Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): bind itx to correct client when extensions are used #19565

Merged
merged 3 commits into from
Jun 5, 2023

Conversation

SevInf
Copy link
Contributor

@SevInf SevInf commented Jun 1, 2023

Previously, when extension callback was called, this within was bound to original client, not transactionProxy. This is relatively easy to fix by preserving this context of the function in which it was called.
Consequence of this change: methods, that are not available on ITX client are now optional within the client extensions. Type change was necessary due to runtime behavior change: since extension context can now be bound to either ITX or normal client, there is no guarantee that those methods would exist.

Related fix: on a type elvel ITXClient was not receiving client components of the extension correctly. Fixed that as well.

@SevInf SevInf added this to the 4.16.0 milestone Jun 1, 2023
@SevInf SevInf requested a review from millsp June 1, 2023 16:01
@SevInf SevInf force-pushed the fix/itx-extensions branch 2 times, most recently from 46a4036 to f0936db Compare June 2, 2023 10:34
@SevInf SevInf marked this pull request as ready for review June 2, 2023 10:45
@SevInf SevInf requested a review from a team as a code owner June 2, 2023 10:45
@SevInf SevInf requested review from aqrln and removed request for a team June 2, 2023 10:45
@millsp
Copy link
Member

millsp commented Jun 2, 2023

Note: Snapshots need updates

@SevInf SevInf merged commit 1f5c9f7 into main Jun 5, 2023
69 checks passed
@SevInf SevInf deleted the fix/itx-extensions branch June 5, 2023 10:28
@Jolg42
Copy link
Member

Jolg42 commented Jun 5, 2023

@SevInf Is this a fix for #17948 (can we close it?)

SevInf added a commit that referenced this pull request Jun 14, 2023
In #19565 we had to change how iTx client calls it's methods.

Previously, it was calling them on default client and appending
transaction information afterwards. After that change, it started
calling them on iTxClient.

Unitended consequence of that: now every cleint property is proxied,
including private properties, private properties of nested object,
returned results, etc. It breaks in a situation like #19653 and #19685.

This PR attempts to rework how itxProxy works. The only thing we need
from itxProxy is ability to pass transaction paramters to the queries
within the callback. Here, it is achieved by introducing a factory for
PrismaPromises that is bound to a specific client instance. When used on
default transaction, factory creates normal promise. ITX client replaces
the default factory with the one that always produces promises, bound to
a specific transaction.

So, instead of deeply proxying everything on itxClient, it creation is
now this:
- replace promise factory with the one that is bound to a transaction
- remove denylist properties
- add TX_ID property

This is better and safer solution to #19565, as well as code
simplification.

Unblocks #19685
SevInf added a commit that referenced this pull request Jun 14, 2023
In #19565 we had to change how iTx client calls it's methods.

Previously, it was calling them on default client and appending
transaction information afterwards. After that change, it started
calling them on iTxClient.

Unitended consequence of that: now every cleint property is proxied,
including private properties, private properties of nested object,
returned results, etc. It breaks in a situation like #19653 and #19685.

This PR attempts to rework how itxProxy works. The only thing we need
from itxProxy is ability to pass transaction paramters to the queries
within the callback. Here, it is achieved by introducing a factory for
PrismaPromises that is bound to a specific client instance. When used on
default transaction, factory creates normal promise. ITX client replaces
the default factory with the one that always produces promises, bound to
a specific transaction.

So, instead of deeply proxying everything on itxClient, it creation is
now this:
- replace promise factory with the one that is bound to a transaction
- remove denylist properties
- add TX_ID property

This is better and safer solution to #19565, as well as code
simplification.

Unblocks #19685
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.

None yet

3 participants