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.88k stars 81 forks source link

No client is generated when prisma generate or prisma db push is run #984

Open AmaseCocoa opened 3 months ago

AmaseCocoa commented 3 months ago

Bug description

No client is generated when prisma generate or prisma db push is run

Log

prisma db push (Cleanup was run before execution and tried to connect to db after execution)

Successfully removed all auto-generated files from C:\Users\AmaseCocoa\Desktop\Hol0\backend\.venv\Lib\site-packages\prisma\__init__.py
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "hol0db", schema "public" at "127.0.0.1:5432"

The database is already in sync with the Prisma schema.

Running generate... - Prisma Client Python (v0.13.1)
Traceback (most recent call last):
  File "C:\Users\AmaseCocoa\Desktop\Hol0\backend\app\utils\migrate.py", line 54, in <module>
    asyncio.run(setup())
  File "C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\AmaseCocoa\Desktop\Hol0\backend\app\utils\migrate.py", line 32, in setup
    db = prisma.Prisma()
         ^^^^^^^^^^^^^
  File "C:\Users\AmaseCocoa\Desktop\Hol0\backend\.venv\Lib\site-packages\prisma\__init__.py", line 53, 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

prisma generate

PS C:\Users\AmaseCocoa\Desktop\Hol0\backend> pdm run prisma generate
Prisma schema loaded from prisma\schema.prisma
PS C:\Users\AmaseCocoa\Desktop\Hol0\backend>

(Logs when prisma generate is run with debugging enabled and with the latest prisma-client-py: prisma.txt)

How to reproduce

Steps to reproduce the behavior:

  1. Execute python -m prisma_cleanup ?
  2. Run prisma generate or prisma db push

Expected behavior

The client is successfully generated and no RuntimeError is generated.

Prisma information

generator client {
    provider = "prisma-client-py"
}

datasource db {
    provider = "postgresql"
    url      = env("DATABASE_URL")
}

model BEConfig {
    id                    String         @id @default("hol0")
    host                  String         @unique

    name                  String @default("Hol0")
    description           String @default("An Interconnected Extensible Microblogging Platform🪐")

    repositoryUrl         String  @default("https://github.com/hol0-dev/backend")
    feedbackUrl           String  @default("https://github.com/hol0-dev/backend/issues")

    admin                 String?
    adminEmail            String?

    maintainerName          String?
    maintainerEmail         String?

    impressumUrl          String?
    tosUrl                String?
    privacyPolicyUrl      String?

    PushNotification      Boolean @default(false)
    SWPublicKey           String?
    SWPrivateKey          String?

    enableMail            Boolean @default(false)
    mailAddress           String?
    smtpHost              String?
    smtpPort              String?
    smtpUser              String?
    smtpPass              String?
    smtpSSL               Boolean @default(false)

    useObjectStorage      Boolean @default(false)
    s3BaseUrl             String?
    s3Bucket              String?
    s3Prefix              String?
    s3Endpoint            String?
    s3Region              String @default("us-east-1")
    s3AccessKey           String?
    s3SecretKey           String?
    s3useSSL              Boolean @default(false)
    s3ForcePathStyle      Boolean @default(false)
    s3setPublicRead       Boolean @default(false)

    enableTurnstile       Boolean @default(false)
    turnstileSiteKey      String?
    turnstileSecretKey    String?

    faviconUrl            String?
    appleTouchIconUrl     String?
    androidTouchIconUrl   String?

    themeColor            String @default("#B0F7DD")
}

model ChannelFollow {
    followeeId String   @id
    channelId  String

    createdAt  DateTime @default(now())

    channel    Channel  @relation(fields: [channelId], references: [id], onDelete: Cascade)
    followee   User     @relation("channelFollowee", fields: [followeeId], references: [id], onDelete: Cascade)
}

model Channel {
    id          String          @id

    name        String
    description String

    remote      String?

    createdAt   DateTime        @default(now()) @map("created_at")
    updatedAt   DateTime        @default(now()) @updatedAt @map("updated_at")

    host        Instance?       @relation(fields: [remote], references: [host])

    followers   ChannelFollow[]
    notes       Note[]
}

model Instance {
    id                      String    @id
    host                    String    @unique

    usersCount              Int       @default(0)
    notesCount              Int       @default(0)

    name                    String?
    description             String?

    iconUrl                 String
    faviconUrl              String
    themeColor              String    @default("#ffffff")

    firstRetrievedAt        DateTime?  @default(now())

    isNotResponding         Boolean?  @default(false)
    isSuspended             Boolean?  @default(false)
    isBlocked               Boolean?  @default(false)
    isSilenced              Boolean?  @default(false)

    softwareName            String?
    softwareVersion         String?
    softwareHomepage        String?

    openRegistrations       Boolean

    adminName               String?
    adminEmail              String?

    maintainerName          String?
    maintainerEmail         String?

    infoUpdatedAt           DateTime  @default(now())
    latestRequestReceivedAt DateTime  @default(now())

    moderationNote          String?

    langs                   String[]

    tosUrl                  String?
    privacyPolicyUrl        String?
    inquiryUrl              String?
    impressumUrl            String?
    repositoryUrl           String?
    feedbackUrl             String?

    channels                Channel[]
    user                    User[]
}

model Reactions {
    id     String @id @default(cuid())

    noteId String
    userId String

    note   Note   @relation(fields: [noteId], references: [id])
    user   User   @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model File {
    id          String   @id
    hash        String   @unique

    url         String

    isSensitive Boolean

    fileSize    Int?
    fileType    String

    caption     String?

    createdAt   DateTime @default(now()) @map("created_at")
    attachedNotes       Note[]   @relation("AttachmentsToNote")
}

model Note {
    id             String        @id

    content        String?
    content_html   String?

    username       String

    createdAt      DateTime      @default(now()) @map("created_at")
    updatedAt      DateTime      @default(now()) @map("updated_at")

    visibility     String
    visibleUserIds String[]

    replyId        String?
    renoteId       String?

    channelId      String?
    channel        Channel?      @relation(fields: [channelId], references: [id], onDelete: Cascade)

    authorId       String
    author         User          @relation(fields: [authorId], references: [id], onDelete: Cascade)

    reactions      Reactions[]
    attachments    File[] @relation("AttachmentsToNote")
}

model Field {
    id          String @id
    authorId    String

    name        String
    value       String

    user        User @relation(fields: [authorId], references: [id])
}

model User {
    id          String @id
    host        String
    username    String

    email       String? @unique
    password    String?

    displayName String?
    description String?

    avatarUrl   String?
    bannerUrl   String?

    bday        DateTime?
    address     String?

    manuallyApprovesFollowers   Boolean @default(false)
    discoverable                Boolean @default(true)

    publicKeyPem String
    publicKeyOwner  String

    privateKeyPem   String?

    accessTokens           AccessToken[]
    channelFollowees ChannelFollow[] @relation("channelFollowee")
    notes       Note[]
    reactions   Reactions[]
    fields      Field[]
    followees   Follow[]       @relation("followee")
    followers   Follow[]       @relation("follower")
    instance    Instance?      @relation(fields: [host], references: [host])
}

model Follow {
    followerId String
    followeeId String

    createdAt  DateTime @default(now())

    followee   User     @relation("followee", fields: [followeeId], references: [id], onDelete: Cascade)
    follower   User     @relation("follower", fields: [followerId], references: [id], onDelete: Cascade)

    @@id([followerId, followeeId])
}

model AccessToken {
    id               String         @id

    createdAt        DateTime       @default(now()) @map("created_at")
    updatedAt        DateTime?       @updatedAt
    expiresAt        DateTime?

    name             String

    scope            String[]

    token            String         @unique

    userId           String
    user             User           @relation(fields: [userId], references: [id], onDelete: Cascade)

    fromWeb          Boolean        @default(false)

    @@index([token])
}

Environment & setup

PS C:\Users\AmaseCocoa\Desktop\Hol0\backend> pdm run prisma py version
prisma                  : 5.11.0
prisma client python    : 0.13.1
platform                : windows
expected engine version : efd2449663b3d73d637ea1fd226bafbcf45b3102
installed extras        : []
install path            : C:\Users\AmaseCocoa\Desktop\Hol0\backend\.venv\Lib\site-packages\prisma
binary cache dir        : C:\Users\AmaseCocoa\.cache\prisma-python\binaries\5.11.0\efd2449663b3d73d637ea1fd226bafbcf45b3102
RobertCraigie commented 3 months ago

Looks like it's failing without an error message for some reason, what happens when you run prisma generate with PRISMA_PY_DEBUG=1?

AmaseCocoa commented 3 months ago

Looks like it's failing without an error message for some reason, what happens when you run prisma generate with PRISMA_PY_DEBUG=1?

I'm out at the moment so I'll try it when I get home.

AmaseCocoa commented 3 months ago

Looks like it's failing without an error message for some reason, what happens when you run prisma generate with PRISMA_PY_DEBUG=1?

[DEBUG  ] prisma.cli.prisma: Running prisma command with args: ['generate']
[DEBUG  ] prisma.cli._node: Checking if nodejs-bin is installed
[DEBUG  ] prisma.cli._node: Checking for global target binary: node
[DEBUG  ] prisma.cli._node: Found global binary at: C:\Program Files\nodejs\node.EXE
[DEBUG  ] prisma.cli._node: node version check exited with code 0
[DEBUG  ] prisma.cli._node: node version check output: v20.14.0
[DEBUG  ] prisma.cli._node: node version check returning (20, 14)
[DEBUG  ] prisma.cli._node: Using global node binary at C:\Program Files\nodejs\node.EXE
[DEBUG  ] prisma.cli._node: Attempting to preprend C:\Program Files\nodejs to the PATH
[DEBUG  ] prisma.cli._node: Using PATH environment variable: C:\Program Files\nodejs;C:\Users\AmaseCocoa\Desktop\Hol0\backend\.venv\Scripts;C:\Users\AmaseCocoa\bin;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\mingw64\bin;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\usr\local\b
in;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\usr\bin;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\usr\bin;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\mingw64\bin;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\usr\bin;C:\Users\AmaseCocoa\bin;C:\Program Files (x86)\VMware\VMware Wor
kstation\bin;C:\ProgramData\scoop\apps\postgresql\current\bin;C:\ProgramData\scoop\shims;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\NVIDIA Corporation\NVIDIA app\NvDLISR;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\cloudflared;C:\Program Files\dotnet;C:\Program Files\PowerShell\7;C:\Users\AmaseCocoa\AppData\
Local\pnpm;C:\Users\AmaseCocoa\.rye\shims;C:\Users\AmaseCocoa\.cargo\bin;C:\Users\AmaseCocoa\go\bin;C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312;C:\Users\AmaseCocoa\scoop\shims;C:\Users\Am
aseCocoa\AppData\Local\Microsoft\WindowsApps;C:\Users\AmaseCocoa\AppData\Local\Programs\Microsoft VS Code\bin;C:\users\amasecocoa\appdata\roaming\python\scripts;C:\Users\AmaseCocoa\.local\bin;C:\Users\AmaseCocoa\AppData\Roaming\npm;C:\Users\AmaseCocoa\AppData\Local\Progr
ams\Ollama;C:\Users\AmaseCocoa\Documents\bin;C:\Users\AmaseCocoa\.dotnet\tools;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\usr\bin\vendor_perl;C:\Users\AmaseCocoa\scoop\apps\git\2.45.2\usr\bin\core_perl
[DEBUG  ] prisma.cli._node: Executing binary at C:\Program Files\nodejs\node.EXE with args: ('C:\\Users\\AmaseCocoa\\.cache\\prisma-python\\binaries\\5.11.0\\efd2449663b3d73d637ea1fd226bafbcf45b3102\\node_modules\\prisma\\build\\index.js', 'generate')
Prisma schema loaded from prisma\schema.prisma
prisma:GeneratorProcess [DEBUG  ] prisma.generator.jsonrpc: Replied with {"id":1,"jsonrpc":"2.0","result":{"manifest":{"prettyName":"Prisma Client Python (v0.13.1)","defaultOutput":"C:\\Users\\AmaseCocoa\\Desktop\\Hol0\\backend\\.venv\\Lib\\site-packages\\prisma","denyli
st":null,"requiresEngines":["queryEngine"],"requiresGenerators":null}}} +2291ms
prisma:GeneratorProcess Traceback (most recent call last): +155ms
prisma:GeneratorProcess   File "C:\Users\AmaseCocoa\Desktop\Hol0\backend\.venv\Lib\site-packages\prisma\generator\generator.py", line 107, in run +0ms
prisma:GeneratorProcess     request = jsonrpc.parse(line) +1ms
prisma:GeneratorProcess               ^^^^^^^^^^^^^^^^^^^ +0ms
prisma:GeneratorProcess   File "C:\Users\AmaseCocoa\Desktop\Hol0\backend\.venv\Lib\site-packages\prisma\generator\jsonrpc.py", line 92, in parse +0ms
prisma:GeneratorProcess     data = json.loads(line) +1ms
prisma:GeneratorProcess            ^^^^^^^^^^^^^^^^ +0ms
prisma:GeneratorProcess   File "C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 346, in loads +0ms
prisma:GeneratorProcess     return _default_decoder.decode(s) +0ms
prisma:GeneratorProcess            ^^^^^^^^^^^^^^^^^^^^^^^^^^ +1ms
prisma:GeneratorProcess   File "C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 337, in decode +0ms
prisma:GeneratorProcess     obj, end = self.raw_decode(s, idx=_w(s, 0).end()) +0ms
prisma:GeneratorProcess                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0ms
prisma:GeneratorProcess   File "C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 353, in raw_decode +0ms
prisma:GeneratorProcess     obj, end = self.scan_once(s, idx) +1ms
prisma:GeneratorProcess                ^^^^^^^^^^^^^^^^^^^^^^ +0ms
prisma:GeneratorProcess json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 548 (char 547) +0ms
prisma:GeneratorProcess [DEBUG  ] prisma.generator.jsonrpc: Replied with {"id":1,"error":{"code":-32000,"message":"Traceback (most recent call last):\n  File \"C:\\Users\\AmaseCocoa\\Desktop\\Hol0\\backend\\.venv\\Lib\\site-packages\\prisma\\generator\\generator.py\", li
ne 107, in run\n    request = jsonrpc.parse(line)\n              ^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\AmaseCocoa\\Desktop\\Hol0\\backend\\.venv\\Lib\\site-packages\\prisma\\generator\\jsonrpc.py\", line 92, in parse\n    data = json.loads(line)\n           ^^^^^^^^^^
^^^^^^\n  File \"C:\\Users\\AmaseCocoa\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\json\\__init__.py\", line 346, in loads\n    return _default_decoder.decode(s)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\AmaseCocoa\\AppData\\Local\\Programs\\Pyth
on\\Python312\\Lib\\json\\decoder.py\", line 337, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\AmaseCocoa\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\json\\decoder.py\"
, line 353, in raw_decode\n    obj, end = self.scan_once(s, idx)\n               ^^^^^^^^^^^^^^^^^^^^^^\njson.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 548 (char 547)","data":{}},"jsonrpc":"2.0"} +0ms
prisma:GeneratorProcess child exited with code 0 on signal null +76ms

It seems that some process has failed and a JSONDecodeError has been generated.

RobertCraigie commented 3 months ago

@AmaseCocoa could you try upgrading to the latest version and share the debug logs? They should now include more helpful information

AmaseCocoa commented 3 months ago

@RobertCraigie

could you try upgrading to the latest version and share the debug logs? They should now include more helpful information

I am attaching it as a txt file because it is too long and I get an error when I try to post it as a comment.

prisma.txt

RobertCraigie commented 2 months ago

@AmaseCocoa I suspect this is an encoding issue somewhere, could you try generating the client using a different encoding?

e.g.

PYTHONIOENCODING=utf-8 python -m prisma generate
AmaseCocoa commented 2 months ago

@AmaseCocoa I suspect this is an encoding issue somewhere, could you try generating the client using a different encoding?

e.g.

PYTHONIOENCODING=utf-8 python -m prisma generate

For some reason, I was able to get it to work by setting PYTHONENCODING to utf-8 and fixing the cp932 related error :)

I'm creating a pull request to fix the encoding error :)

Error:
Traceback (most recent call last):
  File "C:\Users\AmaseCocoa\Desktop\Hol0\beold\.venv\Lib\site-packages\prisma\generator\generator.py", line 106, in run
    self._on_request(request)
  File "C:\Users\AmaseCocoa\Desktop\Hol0\beold\.venv\Lib\site-packages\prisma\generator\generator.py", line 159, in _on_request
    self.generate(data)
  File "C:\Users\AmaseCocoa\Desktop\Hol0\beold\.venv\Lib\site-packages\prisma\generator\generator.py", line 241, in generate
    packaged_schema.write_text(data.datamodel)
  File "C:\Users\AmaseCocoa\AppData\Local\Programs\Python\Python312\Lib\pathlib.py", line 1048, in write_text
    return f.write(data)
           ^^^^^^^^^^^^^
UnicodeEncodeError: 'cp932' codec can't encode character '\U0001fa90' in position 341: illegal multibyte sequence