Errorname / prisma-multi-tenant

🧭 Use Prisma as a multi-tenant provider for your application
MIT License
395 stars 45 forks source link

zero-length delimited identifier at or near "" #65

Closed jimsimon closed 4 years ago

jimsimon commented 4 years ago

Hello!

I'm running into an issue actually using the tenant client. I've successfully set up the management database, added a tenant, and verified that I can connect to that tenant directly via the normal PrismaClient. However when I try to use MultiTenant, I get the following error:

zf [Error]: 
Invalid `prisma.tenant.findOne()` invocation:

  Error in connector: Error querying the database: db error: ERROR: zero-length delimited identifier at or near """"
    at $w.request (/usr/src/app/node_modules/.prisma-multi-tenant/management/runtime/index.js:212:257)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  clientVersion: '2.9.0'
}

Here's my test code:

import { MultiTenant } from '@prisma-multi-tenant/client'
import { PrismaClient } from "@prisma/client";

const multiTenant = new MultiTenant<PrismaClient>()

async function main() {
  const prisma = await multiTenant.get('dev')
  const sites = await prisma.site.findMany()

  console.log(sites)
}

main()
  .catch(e => console.error(e))
  .finally(async () => {
    await multiTenant.disconnect()
  })

I'm using the latest version of Prisma (2.9.0) and working with Postgres database. I'm using one database instance but differentiating between tenants via schema in the connection string.

DATABASE_URL=postgresql://postgres@db:5432/app?schema=dev MANAGEMENT_URL=postgresql://postgres@db:5432/app?schema=public

jimsimon commented 4 years ago

I believe I found the problem...

I added a console.log(process.env.MANAGEMENT_URL) and it appears the =dev part of the url is being lost. This only seems to be a problem for the management environment variable. Since I'm using the default schema, I'm able to workaround this issue by removing the entire ?schema=public part.

jimsimon commented 4 years ago

After doing some more research, I suspect this might be related to being unable to use quotes for the management url (#60). It might also be related to how the url is being read or parsed somewhere in the code.

Errorname commented 4 years ago

Hi @jimsimon! Thanks for reporting the issue. 🙏 It may indeed come from #60 which has been resolved with the release of prisma-multi-tenant 2.4.1. Don't hesitate to reopen if you still encounter the issue after upgrading!