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

Bug: Pydantic validation aliases are not handled by coverage #577

Open
1 of 4 tasks
vrslev opened this issue Aug 14, 2024 · 1 comment
Open
1 of 4 tasks

Bug: Pydantic validation aliases are not handled by coverage #577

vrslev opened this issue Aug 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@vrslev
Copy link

vrslev commented Aug 14, 2024

Description

ModelFactory.coverage() fails on models that have validation_alias set

MCVE

import typing

import pydantic
from polyfactory.factories.pydantic_factory import ModelFactory


class C(pydantic.BaseModel):
    a: typing.Annotated[str, pydantic.Field(validation_alias="b")]


class CFactory(ModelFactory[C]):
    pass


for _ in CFactory.coverage():
    pass

Logs

pydantic_core._pydantic_core.ValidationError: 1 validation error for C
b
  Field required [type=missing, input_value={'a': 'FdhLXuyqOfQSYmiqClUe'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.7/v/missing

Release Version

2.16.2

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@vrslev vrslev added the bug Something isn't working label Aug 14, 2024
@adhtruong
Copy link
Collaborator

adhtruong commented Oct 2, 2024

Hi vrslev, this may be tricky to support as is given validation_alias may not be a str but an alias path as well. I will have a look to see if this can be done whilst being backwards compatible.

I would suggest setting populate_by_name on the pydantic model as a workaround in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants