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

Enums in included relations are raw strings #1059

Open
lokmeinmatz opened this issue Jan 6, 2025 · 0 comments
Open

Enums in included relations are raw strings #1059

lokmeinmatz opened this issue Jan 6, 2025 · 0 comments

Comments

@lokmeinmatz
Copy link

Bug description

String Enums are not casted to their enum type on relations (with include included entities)

How to reproduce

Schema:

datasource db {
  provider = "postgresql"
  url      = "postgresql://postgres:postgres@localhost:4321/postgres"
}

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

model Action {
    id String @id @default(cuid())
    executions Execution[]
}

enum Executor {
    USER
    SYSTEM
}

model Execution {
    id String @id @default(cuid())
    actionId String
    action Action @relation(fields: [actionId], references: [id])
    executor Executor
}

Code:

import asyncio
import prisma
import logging
logging.basicConfig()
logging.getLogger('prisma').setLevel(logging.DEBUG)

db = prisma.Prisma()


async def main():
    await db.connect()
    await db.execution.delete_many()
    await db.action.delete_many()

    action = await db.action.create(
        data={"executions": {"create": {"executor": "USER"}}},
        include={"executions": True},
    )

    direct_enum = (await db.execution.find_first(where={"executor": "USER"})).executor
    print("type(direct_enum)", type(direct_enum))

    if not action.executions or not action.executions[0].executor:
        raise ValueError("No executions found")

    relation_enum = action.executions[0].executor
    print("type(relation_enum)", type(relation_enum))
    assert isinstance(direct_enum, prisma.enums.Executor)
    assert isinstance(relation_enum, prisma.enums.Executor)


asyncio.run(main())

the second assert fails because relation_enum is a raw string. The same happens with any "include" query, like create, update etc.

Expected behavior

enums are always cast to enums, no matter if they are in the "direct" entity or included through a relation

Prisma information

Environment & setup

  • OS: Osx 15.1
  • Database: Postgres
  • Python version: 3.12
  • Prisma version: 0.15.0
prisma                  : 5.17.0
prisma client python    : 0.15.0
platform                : darwin
expected engine version : 393aa359c9ad4a4bb28630fb5613f9c281cde053
installed extras        : []
install path            : /Users/matthias/Dev/tests/.venv/lib/python3.12/site-packages/prisma
binary cache dir        : /Users/matthias/.cache/prisma-python/binaries/5.17.0/393aa359c9ad4a4bb28630fb5613f9c281cde053
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

1 participant