Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Multiple levels of nested creates or includes do not exhibit correct syntax highlighting #1068

@szvsw

Description

@szvsw

Bug description

When using multiple nested levels of create or include, the pylance syntax highlighting is incorrect. For instance, it highlights a second level of create as a reportArgumentType error even though it will execute perfectly fine.

Perhaps this is user error, but I believe I have everything set up correctly with recursive types etc.

How to reproduce

from prisma import Prisma
from prisma.models import Child, Parent, SubChild


async def main():
    """This is the main function that runs the demo."""
    db = Prisma(auto_register=True)
    await db.connect()
    # delete everything in the db
    await Parent.prisma().delete_many()
    await Child.prisma().delete_many()
    await SubChild.prisma().delete_many()

    async with db.tx() as tx:
        arthur = await Parent.prisma(tx).create(
            data={
                "name": "Arthur",
                "child": {
                    "create": {
                        "name": "Billie",
                        # this incorrectly shows a pylance error, since multiple nested creates do work.
                        # [reportArgumentType: subChild is an undefined item in type "ChildCreateWithoutRelationsInput"]
                        "subChild": {
                            "create": {
                                "name": "Carl",
                            },
                        },
                    },
                },
            },
            include={
                "child": {
                    "include": {
                        "subChild": True,
                    },
                },
            },
        )
    print(arthur.child.subChild.name)


async def create_parent(db: Prisma):
    """Some examples of syntax highlighting behavior."""
    async with db.tx() as tx:
        await Parent.prisma(tx).create(
            data={
                "name": "Adam",
                # This should show a pylance/pyright error because there is no childId or child:create
            }
        )
        await Parent.prisma(tx).create(
            data={
                # This correctly shows a pylance/pyright error because there is an incorrect field name
                # [reportArgumentType: nam is an undefined item in type "ParentCreateInput"]
                "nam": "Alex",
                "child": {
                    "create": {
                        "name": "Bob",
                    },
                },
            }
        )

        await Parent.prisma(tx).create(
            # this correctly shows a pylance/pyright error because there is no name
            # [reportArgumentType: name is required in "ParentCreateInput"]
            data={
                "child": {
                    "create": {
                        "name": "Bob",
                    },
                },
            }
        )

        await Parent.prisma(tx).create(
            data={
                "name": "Alfred",
                "child": {
                    "create": {
                        # this should show an error because the subchild is not defined
                        "name": "Bob",
                    },
                },
            }
        )

        await Parent.prisma(tx).create(
            data={
                "name": "Andy",
                "child": {
                    "create": {
                        "name": "Bob",
                        # this incorrectly shows a pylance error, since multiple nested creates do work.
                        # [reportArgumentType: subChild is an undefined item in type "ChildCreateWithoutRelationsInput"]
                        "subChild": {
                            "create": {
                                "name": "Charlie",
                            },
                        },
                    },
                },
            }
        )

        arthur = await Parent.prisma(tx).create(
            data={
                "name": "Arthur",
                "child": {
                    "create": {
                        "name": "Billie",
                        # this incorrectly shows a pylance error, since multiple nested creates do work.
                        # [reportArgumentType: subChild is an undefined item in type "ChildCreateWithoutRelationsInput"]
                        "subChild": {
                            "create": {
                                "name": "Carl",
                            },
                        },
                    },
                },
            },
            include={
                "child": {
                    "include": {
                        "subChild": True,
                    },
                },
            },
        )
        # this incorrectly shows a syntax error, since child:include:subChild:True and child/childId are not optional in parent
        # and subChild/subChildId are not optional in child.
        carls_name = arthur.child.subChild.name
        print(carls_name)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Expected behavior

  • No errors to show when accessing an object returned from a select when using multiple levels of include on fields that are all fully required in the schema.
  • An error to show when creating a record with a relation that is required but not present
  • No error shows when creating a second level of nested creates.

Prisma information

datasource db {
    provider = "sqlite"
    url      = "file:database.db"
}

generator client {
    provider             = "prisma-client-py"
    interface            = "asyncio"
    recursive_type_depth = -1
}

model Parent {
    id   String @id @default(uuid())
    name String

    childId String
    child   Child  @relation("ParentChild", fields: [childId], references: [id])
}

model Child {
    id   String @id @default(uuid())
    name String

    subChildId String
    subChild   SubChild @relation("ChildSubChild", fields: [subChildId], references: [id])

    parents Parent[] @relation("ParentChild")
}

model SubChild {
    id   String @id @default(uuid())
    name String

    subChildOf Child[] @relation("ChildSubChild")
}

Environment & setup

  • OS: Windows
  • Database: SQLite
  • Python version: 3.10
  • IDE: cursor & vscode both exhibit same behavior with latest microsoft python/pylance.
  • pyproject.toml contains:
[tool.pyright]
include = ["epinterface"]
typeCheckingMode = "standard"
venvPath = "."
venv = ".venv"
  • Prisma version:
prisma                  : 5.17.0
prisma client python    : 0.15.0
platform                : windows
expected engine version : 393aa359c9ad4a4bb28630fb5613f9c281cde053
installed extras        : ['docs']
install path            : C:\Users\szvsw\repos\epinterface\.venv\Lib\site-packages\prisma
binary cache dir        : C:\Users\szvsw\.cache\prisma-python\binaries\5.17.0\393aa359c9ad4a4bb28630fb5613f9c281cde053

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions