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

false-positive warning wiht pydantic 2.6.0 "Unexpected extra items present in tuple" #8677

Closed
1 task done
Tracked by #8671
schenker opened this issue Jan 30, 2024 · 2 comments · Fixed by pydantic/pydantic-core#1174
Closed
1 task done
Tracked by #8671
Assignees
Labels
bug V2 Bug related to Pydantic V2

Comments

@schenker
Copy link

schenker commented Jan 30, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

With pydantic 2.6.0 the example below gives me a false positive warning:

from pydantic import BaseModel

class Point(BaseModel):
    coordinates: tuple[float, float] | tuple[float, float, float]

print(Point(coordinates=(1.0, 2.0)).model_dump())
print(Point(coordinates=(1.0, 2.0, 3.0)).model_dump())

Output:

{'coordinates': (1.0, 2.0)}
/home/me/workspace/myproject/venv/lib/python3.10/site-packages/pydantic/main.py:314: UserWarning: Pydantic serializer warnings:
  Unexpected extra items present in tuple
  return self.__pydantic_serializer__.to_python(
{'coordinates': (1.0, 2.0, 3.0)}

With pydantic 2.5.3 the example does not produce any warnings.

Example Code

from pydantic import BaseModel

class Point(BaseModel):
    coordinates: tuple[float, float] | tuple[float, float, float]

print(Point(coordinates=(1.0, 2.0)).model_dump())
print(Point(coordinates=(1.0, 2.0, 3.0)).model_dump())

Python, Pydantic & OS Version

$ python -c "import pydantic.version; print(pydantic.version.version_info())"
             pydantic version: 2.6.0
        pydantic-core version: 2.16.1
          pydantic-core build: profile=release pgo=true
                 install path: /home/me/workspace/myproject/venv/lib/python3.10/site-packages/pydantic
               python version: 3.10.13 (main, Aug 25 2023, 13:20:03) [GCC 9.4.0]
                     platform: Linux-5.15.0-91-generic-x86_64-with-glibc2.31
             related packages: mypy-1.8.0 typing_extensions-4.9.0
                       commit: unknown
@schenker schenker added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Jan 30, 2024
@sydney-runkle
Copy link
Member

@schenker,

Thanks for the report. We'll look into a fix for this to be included in a patch release soon!

@schenker
Copy link
Author

schenker commented Feb 2, 2024

Thanks for the quick fix!

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

Successfully merging a pull request may close this issue.

2 participants