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

AttributeError: module 'prisma.fields' has no attribute 'Base64' #1056

Open
ZainyAct opened this issue Dec 22, 2024 · 2 comments
Open

AttributeError: module 'prisma.fields' has no attribute 'Base64' #1056

ZainyAct opened this issue Dec 22, 2024 · 2 comments

Comments

@ZainyAct
Copy link

Bug description

The Prisma Python Client generates a reference to fields.Base64 in the _builder.py file, but the Base64 type is not defined in the generated fields.py. This causes an AttributeError: module 'prisma.fields' has no attribute 'Base64' during prisma generate.

How to reproduce

Steps to reproduce the behavior:

  1. Use the following Prisma schema:
    generator client {
      provider = env("PRISMA_CLIENT_PROVIDER")
    }
    
    datasource db_postgres {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    model Example {
      id   Int    @id @default(autoincrement())
      data Bytes
    }
    

Expected behavior

The Prisma Python Client should generate the Base64 type in fields.py or provide proper handling for the Bytes type without generating a broken reference.
Prisma information

generator client {
provider = env("PRISMA_CLIENT_PROVIDER")
}

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

model Example {
id Int @id @default(autoincrement())
data Bytes
}

Environment & setup

OS: Ubuntu 20.04
Database: PostgreSQL
Python version: 3.10
Prisma version:

Name: prisma
Version: 0.15.0

Name: prisma-client
Version: 0.2.1

@rsonger
Copy link

rsonger commented Dec 24, 2024

I was getting this same error except it occurred when I ran from prisma import Prisma in a Python program or repl after generating the client one time. Then the error would occur each time I tried to regenerate with prisma generate after that. And the prisma_cleanup module didn't help either because it would give the error
RuntimeError: The given package does not appear to be a Prisma Client Python package.

I was able to fix this by reinstalling prisma and specifying recursive_type_depth = 5 for the generator in my schema.prisma. The warnings about Mypy lead me to try with this set to -1, but that is when I started getting the error about fields.Base64. I could verify that generating with recursive_type_depth = 5 gives a fields.py file containing only the following line instead of the version of fields.py that does not import from ._fields or base64.
from ._fields import *

Here is the generator in my schema.prisma file with the fix:

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

@ZainyAct
Copy link
Author

So it turns out the issue was with using python "prisma-client-py" as the provider, if I used js "prisma-client-js"everything worked out fine. I know that isn't much of a fix but its better than punching your desk for 3 hours (my hands hurt).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants