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

DataProxy Client only works if I instantiate a normal Client first #12682

Closed
janpio opened this issue Apr 5, 2022 · 1 comment
Closed

DataProxy Client only works if I instantiate a normal Client first #12682

janpio opened this issue Apr 5, 2022 · 1 comment
Assignees
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. topic: data proxy
Milestone

Comments

@janpio
Copy link
Member

janpio commented Apr 5, 2022

This is a suuuuper weird problem that I encountered when doing not very common things, so it is probably an edge case, but still super interesting.

Here is the reproduction: https://github.com/janpio/prisma-3.12.0_simple/tree/weird
Get the .env content from this internal conversation in #prisma-data-proxy: https://prisma-company.slack.com/archives/C02C34KRHBQ/p1649182410797739
When you npm install and then npx ts-node scripts.ts this should happen:

C:\Users\Jan\Documents\throwaway\3.12.0_simple>npx ts-node scripts.ts
C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma\dataproxy\runtime\proxy.js:96
It should have this form: { url: "CONNECTION_STRING" }`);if(typeof a!="string")throw new Re(`Invalid value ${JSON.stringify(a)} for datasource "${r}" provided to PrismaClient constructor.
                                                                                     ^
PrismaClientConstructorValidationError: Invalid value undefined for datasource "db" provided to PrismaClient constructor.
It should have this form: { url: "CONNECTION_STRING" }
Read more at https://pris.ly/d/client-constructor
    at Object.datasources (C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma\dataproxy\runtime\proxy.js:96:86)
    at validatePrismaClientOptions (C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma\dataproxy\runtime\proxy.js:97:1841)
    at new PrismaClient (C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma\dataproxy\runtime\proxy.js:104:541)
    at Object.<anonymous> (C:\Users\Jan\Documents\throwaway\3.12.0_simple\scripts.ts:7:25)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Module.m._compile (C:\Users\Jan\Documents\throwaway\3.12.0_simple\node_modules\ts-node\src\index.ts:1455:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Object.require.extensions.<computed> [as .ts] (C:\Users\Jan\Documents\throwaway\3.12.0_simple\node_modules\ts-node\src\index.ts:1458:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

This error message already looks invalid, as the code looks exactly like that.

Now uncomment lines 4 to 6, and this changes:

C:\Users\Jan\Documents\throwaway\3.12.0_simple>npx ts-node scripts.ts
  prisma:tryLoadEnv Environment variables loaded from C:\Users\Jan\Documents\throwaway\3.12.0_simple\.env +0ms
  prisma:tryLoadEnv Environment variables loaded from C:\Users\Jan\Documents\throwaway\3.12.0_simple\.env +3ms
  prisma:client dirname C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma\library +0ms
  prisma:client relativePath .. +0ms
  prisma:client cwd C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma +1ms
  prisma:client clientVersion: 3.12.0 +2ms
  prisma:client clientEngineType: library +0ms
  prisma:client:libraryEngine internalSetup +0ms
prisma:query query {
  findManyFoo {
    id
    name
  }
}
  prisma:client:libraryEngine Searching for Query Engine Library in C:\Users\Jan\Documents\throwaway\3.12.0_simple\.prisma\client +71ms
  prisma:client:libraryEngine Searching for Query Engine Library in C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma\library +1ms
  prisma:client:libraryEngine loadEngine using C:\Users\Jan\Documents\throwaway\3.12.0_simple\prisma\library\query_engine-windows.dll.node +1ms
prisma:info Calling https://aws-us-east-1.prisma-data.com/3.12.0/11e52bd7ecad95f9f3809fd9d8fec1533840f048c3c245ce8b703d8ff19d2fb3/graphql (n=0)
foo proxy [ { id: '624c5afcef6abe4179942612', name: 'foo' } ]
  prisma:client:libraryEngine hookProcess received: beforeExit +2s
  prisma:client:libraryEngine runBeforeExit +1ms
  prisma:client:libraryEngine hookProcess received: exit +1ms

(Using 3.12.0)

@janpio janpio added 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. topic: data proxy labels Apr 5, 2022
@janpio
Copy link
Member Author

janpio commented Apr 5, 2022

Turns out, the data proxy Client is not loading the .env file and hence the env var is not defined. Setting it manually before executing the script makes it run as it should. Seems the new PrismaClient() for DataProxy is missing some logic.

@millsp millsp self-assigned this Jun 1, 2022
@millsp millsp added this to the 3.15.0 milestone Jun 1, 2022
@millsp millsp closed this as completed Jun 7, 2022
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. topic: data proxy
Projects
None yet
Development

No branches or pull requests

3 participants