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

AliasChoices Unhashable When Comparing Models #9220

Closed
1 task done
iambroadband opened this issue Apr 12, 2024 · 4 comments · Fixed by #9223
Closed
1 task done

AliasChoices Unhashable When Comparing Models #9220

iambroadband opened this issue Apr 12, 2024 · 4 comments · Fixed by #9223
Assignees
Labels
bug V2 Bug related to Pydantic V2

Comments

@iambroadband
Copy link

iambroadband commented Apr 12, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

While upgrading from Pydantic v2.6.4 to v2.7.0 some of our tests comparing models started failing. My expectation here is that we'd be able to continue comparing models constructed in this way without any issue. The results here do not meet that expectation because we encounter a TypeError

image

Example Code

from pydantic import AliasChoices, BaseModel, Field

class MyModel(BaseModel):
    data: str
    our_id: str | None = Field(
        default=None,
        validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"),
    )

def test_cardmodel_eq():
    model1 = MyModel.model_construct(data="test data")
    model2 = MyModel.model_construct(data="test data")
    model3 = MyModel.model_construct(data="other data")
    assert model1 == model2
    assert not model1 == model3

Python, Pydantic & OS Version

pydantic version: 2.7.0
pydantic-core version: 2.18.1
pydantic-core build: profile=release pgo=true
install path: /home/broadband/.cache/pypoetry/virtualenvs/scooze-iup8854z-py3.11/lib/python3.11/site-packages/pydantic
python version: 3.11.5 (main, Aug 26 2023, 21:51:13) [GCC 11.3.0]
platform: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
related packages: fastapi-0.110.1 pydantic-settings-2.2.1 typing_extensions-4.11.0
commit: unknown
@iambroadband iambroadband added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 12, 2024
@sydney-runkle
Copy link
Member

@iambroadband,

Thanks for reporting this! We'll roll a fix out with a patch release early next week!

@sydney-runkle
Copy link
Member

Closing this as a dupe of #9216, but will make sure to resolve this in the patch release!

@sydney-runkle sydney-runkle closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
@sydney-runkle sydney-runkle self-assigned this Apr 12, 2024
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Apr 12, 2024
@sydney-runkle
Copy link
Member

@iambroadband,

I don't think your test as it stands should pass - model1 and model2 aren't equivalent, unless I'm missing something?

@iambroadband
Copy link
Author

iambroadband commented Apr 12, 2024

@sydney-runkle

I see I have made a typo when writing my example code 🤦🏼I will fix it. It should be fixed now. Even when they should be equivalent this test is failing on a TypeError, but it seems like #9223 is addressing that?

Thank you 🙏 appreciate everything you all do.

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