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

unhashable type: 'AliasPath' raised from BaseModel.model_construct() #9239

Closed
1 task done
jessemyers-lettuce opened this issue Apr 13, 2024 · 1 comment
Closed
1 task done
Labels
bug V2 Bug related to Pydantic V2
Milestone

Comments

@jessemyers-lettuce
Copy link

jessemyers-lettuce commented Apr 13, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

This issue appears to be a regression in 2.7.0; we did not see this issue in our code with 2.6.4

Traceback:

Traceback (most recent call last):
  File "/path/to/main.py", line 9, in <module>
    example = Example.model_construct(value="value")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.12/site-packages/pydantic/main.py", line 228, in model_construct
    elif field.validation_alias is not None and field.validation_alias in values:
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'AliasPath'

Example Code

#!/usr/bin/env python3
from pydantic import AliasPath, BaseModel, Field

class Example(BaseModel):
    value: str = Field(validation_alias=AliasPath("data", "value"))


if __name__ == "__main__":
    example = Example.model_construct(value="value")
    assert example.value == "value"

Python, Pydantic & OS Version

pydantic version: 2.7.0
pydantic-core version: 2.18.1
pydantic-core build: profile=release pgo=true
install path: /path/to/.venv/lib/python3.12/site-packages/pydantic
python version: 3.12.2 (main, Feb 13 2024, 20:25:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
platform: macOS-14.4.1-arm64-arm-64bit
related packages: typing_extensions-4.11.0
commit: unknown
@jessemyers-lettuce jessemyers-lettuce added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 13, 2024
@sydney-runkle sydney-runkle added this to the 2.7 fixes milestone Apr 13, 2024
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Apr 13, 2024
@sydney-runkle
Copy link
Member

Hi @jessemyers-lettuce,

This is fixed on main by #9223. We'll do a patch release with this fix early next week!

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

No branches or pull requests

2 participants