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

Unable to pass list[Literal[...]] as parameter to in filter #981

Open
rijenkii opened this issue Jul 23, 2024 · 0 comments
Open

Unable to pass list[Literal[...]] as parameter to in filter #981

rijenkii opened this issue Jul 23, 2024 · 0 comments
Labels
kind/improvement An improvement to existing feature and code. topic: types An issue or improvement to typing
Milestone

Comments

@rijenkii
Copy link

Bug description

Passing a list of literal values to a where={"field": {"in": here}} causes pyright to throw a following error:

/tmp/tmp.EUgRheGXMj/main.py
  /tmp/tmp.EUgRheGXMj/main.py:12:39 - error: Argument of type "dict[str, dict[str, list[Literal['1', '2', '3']]]]" cannot be assigned to parameter "where" of type "TestWhereInput | None" in function "find_many"
    Type "dict[str, dict[str, list[Literal['1', '2', '3']]]]" is incompatible with type "TestWhereInput | None"
      "dict[str, dict[str, list[Literal['1', '2', '3']]]]" is incompatible with "TestWhereInput"
      "dict[str, dict[str, list[Literal['1', '2', '3']]]]" is incompatible with "None" (reportArgumentType)
1 error, 0 warnings, 0 informations 

How to reproduce

from typing import Literal
from typing import cast

from prisma import Prisma


async def main() -> None:
    prisma = Prisma()

    listStr = ["1", "2", "3"]
    await prisma.test.find_many(where={"id": {"in": listStr}})

    listLiteral = cast(list[Literal["1", "2", "3"]], ["1", "2", "3"])
    await prisma.test.find_many(where={"id": {"in": listLiteral}})

Expected behavior

Expected to be able to pass a list of string literals as argument to in.

Prisma information

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

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

model Test {
  id String @id
}

Environment & setup

  • OS: Fedora 40
  • Database: PostgreSQL
  • Python version: 3.12.4
  • Prisma version:
    prisma                  : 5.11.0
    prisma client python    : 0.13.1
    platform                : debian-openssl-3.2.x
    expected engine version : efd2449663b3d73d637ea1fd226bafbcf45b3102
    installed extras        : []
    install path            : /tmp/tmp.EUgRheGXMj/.venv/lib/python3.12/site-packages/prisma
    binary cache dir        : /home/rijenkii/.cache/prisma-python/binaries/5.11.0/efd2449663b3d73d637ea1fd226bafbcf45b3102
    

Additional info

This can be fixed by replacing List[str] in the generated types with Sequence[str]:
https://pyright-play.net/?strict=true&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAySMApiAIYA2ANFAMbkDOMtAyiQI4CuJKdJAKAGUkzIqQqUoAXnpMYAChHMA2uLJUVAIgCMW2loBM%2BqFoDMWgLqXa2vQeMGLlgJRCA%2BjoBcUZTBXMIJYyvqIw6pIC7oY%2B7Ny8-AEwQSF%2BEVQCQA

Expression of type "list[Literal['1', '2', '3']]" is incompatible with declared type "list[str]"
  "list[Literal['1', '2', '3']]" is incompatible with "list[str]"
    Type parameter "_T@list" is invariant, but "Literal['1', '2', '3']" is not the same as "str"
    Consider switching from "list" to "Sequence" which is covariant  (reportAssignmentType)
@RobertCraigie RobertCraigie added kind/improvement An improvement to existing feature and code. topic: types An issue or improvement to typing labels Jul 23, 2024
@RobertCraigie RobertCraigie added this to the 0.15.0 milestone Aug 4, 2024
@RobertCraigie RobertCraigie modified the milestones: 0.15.0, 0.16.0 Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. topic: types An issue or improvement to typing
Projects
None yet
Development

No branches or pull requests

2 participants