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

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

Open
szvsw opened this issue Mar 6, 2025 · 0 comments

Comments

@szvsw
Copy link

szvsw commented Mar 6, 2025

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
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