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

$on query event subscriptions for extended clients actually get applied to the underlying base client #18724

Open
mziwisky opened this issue Apr 13, 2023 · 0 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: extend-client Extending the Prisma Client

Comments

@mziwisky
Copy link

mziwisky commented Apr 13, 2023

Bug description

with an express app, I want to log every SQL query with its associated request ID (e.g. see #7596). i thought i might be able to pull this off by creating an extended client per request as suggested here, but when i attach a 'query' event listener to the extended client, it actually gets applied to the base client instead.

same thing is described here: #16500 (comment) (the comment right after that one requests that the poster open a new issue for this, but i couldn't find one, so i'm opening this one)

How to reproduce

const extended1 = prismaClient.$extends({});
extended1.$on('query', (e) => {
  console.log('query from ext1');      
});
const extended2 = prismaClient.$extends({});
extended2.$on('query', (e) => {
  console.log('query from ext2');      
});
await extended1.user.count()
// log: query from ext1
// log: query from ext2

Expected behavior

there should only be one log line, query from ext1

Prisma information

issue is independent of any particular prisma schema

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v16.14.0

Prisma Version

prisma                  : 4.7.1
@prisma/client          : 4.7.1
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 272861e07ab64f234d3ffc4094e32bd61775599c (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.7.1-1.272861e07ab64f234d3ffc4094e32bd61775599c
Default Engines Hash    : 272861e07ab64f234d3ffc4094e32bd61775599c
Studio                  : 0.477.0
@mziwisky mziwisky added the kind/bug A reported bug. label Apr 13, 2023
@Weakky Weakky added team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: extend-client Extending the Prisma Client bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: extend-client Extending the Prisma Client
Projects
None yet
Development

No branches or pull requests

2 participants