RobertCraigie / prisma-client-py

Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
https://prisma-client-py.readthedocs.io
Apache License 2.0
1.83k stars 77 forks source link

Compatibility with Vercel #692

Open miquelmassot opened 1 year ago

miquelmassot commented 1 year ago

Bug description

The python client is apparently not working correctly with vercel. Upon deployment, the software complains about not being deployed despite having issued the commands. The repository I am using is https://github.com/miquelmassot/remote_awareness_web_server.

How to reproduce

  1. Clone, enter the venv of remote_awareness_web_server and npm install.
  2. Generate the prisma client
    
    05:01:09 (venv) miquel@angler remote_awareness_web_server ±|main ✗|→ prisma generate
    Environment variables loaded from .env
    Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client Python (v0.8.0) to ./venv/lib/python3.10/site-packages/prisma in 137ms


2. Push the DB
```bash
05:01:14 (venv) miquel@angler remote_awareness_web_server ±|main ✗|→ prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "db.phjashzcpxcmghjzfswm.supabase.co:5432"

The database is already in sync with the Prisma schema.

✔ Generated Prisma Client Python (v0.8.0) to ./venv/lib/python3.10/site-packages/prisma in 139ms
  1. Deploy the website with vercel.
    05:01:23 (venv) miquel@angler remote_awareness_web_server ±|main ✗|→ vercel dev
    Vercel CLI 28.15.3
    > Ready! Available at http://localhost:3000
    > Building @vercel/python@latest:api/index.py
    Installing required dependencies...
    > Built @vercel/python@latest:api/index.py [33s]
    Traceback (most recent call last):
    File "/home/miquel/.cache/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 147, in <module>
    lambda_runtime_main()
    File "/home/miquel/.cache/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 127, in lambda_runtime_main
    fn = lambda_runtime_get_handler()
    File "/home/miquel/.cache/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 113, in lambda_runtime_get_handler
    mod = importlib.import_module(module_name)
    File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 883, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "/tmp/zeit-fun-3ff47dfcd078a/vc__handler__python.py", line 13, in <module>
    __vc_spec.loader.exec_module(__vc_module)
    File "<frozen importlib._bootstrap_external>", line 883, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "/tmp/zeit-fun-3ff47dfcd078a/./api/index.py", line 6, in <module>
    from prisma import Prisma, register
    File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
    File "/tmp/zeit-fun-3ff47dfcd078a/prisma/__init__.py", line 43, in __getattr__
    raise RuntimeError(
    RuntimeError: The Client hasn't been generated yet, you must run `prisma generate` before you can use the client.
    See https://prisma-client-py.readthedocs.io/en/stable/reference/troubleshooting/#client-has-not-been-generated-yet
    TypeError: Object prototype may only be an Object or null: undefined
    at Function.setPrototypeOf (<anonymous>)
    at new LambdaError (/usr/local/lib/node_modules/vercel/dist/index.js:8624:16)
    at Lambda.<anonymous> (/usr/local/lib/node_modules/vercel/dist/index.js:8757:27)
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/vercel/dist/index.js:8671:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    Traceback (most recent call last):
    File "/home/miquel/.cache/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 147, in <module>
    lambda_runtime_main()
    File "/home/miquel/.cache/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 127, in lambda_runtime_main
    fn = lambda_runtime_get_handler()
    File "/home/miquel/.cache/com.vercel.fun/runtimes/python3/../python/bootstrap.py", line 113, in lambda_runtime_get_handler
    mod = importlib.import_module(module_name)
    File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 883, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "/tmp/zeit-fun-3ff47dfcd078a/vc__handler__python.py", line 13, in <module>
    __vc_spec.loader.exec_module(__vc_module)
    File "<frozen importlib._bootstrap_external>", line 883, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "/tmp/zeit-fun-3ff47dfcd078a/./api/index.py", line 6, in <module>
    from prisma import Prisma, register
    File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
    File "/tmp/zeit-fun-3ff47dfcd078a/prisma/__init__.py", line 43, in __getattr__
    raise RuntimeError(
    RuntimeError: The Client hasn't been generated yet, you must run `prisma generate` before you can use the client.
    See https://prisma-client-py.readthedocs.io/en/stable/reference/troubleshooting/#client-has-not-been-generated-yet
    TypeError: Object prototype may only be an Object or null: undefined
    at Function.setPrototypeOf (<anonymous>)
    at new LambdaError (/usr/local/lib/node_modules/vercel/dist/index.js:8624:16)
    at Lambda.<anonymous> (/usr/local/lib/node_modules/vercel/dist/index.js:8757:27)
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/vercel/dist/index.js:8671:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Expected behavior

Deployment to work straightaway.

Prisma information

// schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator py {
  provider             = "prisma-client-py"
  interface            = "sync"
  recursive_type_depth = 5
}

model Message {
  id          Int       @id @default(autoincrement())
  content     Bytes
  platform    Platform? @relation(fields: [platform_id], references: [id])
  platform_id Int?
  image       Image?    @relation(fields: [image_id], references: [id])
  image_id    Int?
  created_at  DateTime  @default(now())
}

model Image {
  id           Int       @id @default(autoincrement())
  timestamp    DateTime
  latitude     Float
  longitude    Float
  latent_space Float[]
  platform     Platform  @relation(fields: [platform_id], references: [id])
  platform_id  Int
  data         Bytes?
  Message      Message[]
}

model Platform {
  id         Int       @id @default(autoincrement())
  name       String?
  created_at DateTime  @default(now())
  updated_at DateTime  @updatedAt
  messages   Message[]
  images     Image[]
}

Environment & setup

RobertCraigie commented 1 year ago

I suspect this issue is something to do with how Vercel bundles Python packages. I'm not familiar with what they do under the hood.

What is in the tmp/zeit-fun-3ff47dfcd078a/prisma/ directory?

RobertCraigie commented 1 year ago

I'd also recommend trying generating to a local directory to see how Vercel handles that, for example:

generator py {
  provider = "prisma-client-py"
  output = "prisma"
}
sshah98 commented 5 months ago

was there any fix that worked for this? I have the same exact issue here. I tried changing the output as well as updating the build. Even changed it to python3 -m prisma -- didn't work

roromainlcs commented 3 months ago

i have the same issue and when i tried to execute python scripts on vercel i couldn't do it and found this issue https://github.com/vercel/next.js/discussions/46223#discussion-4884240 vercel just don t put any python runtime on their server image I currently have this vercel error when trying to do prisma generate before build