Skip to content

Bug: ModelFactory doesn't support pydantic EmailStr Field constraints #642

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

Open
1 of 4 tasks
suspiciousRaccoon opened this issue Feb 7, 2025 · 0 comments
Open
1 of 4 tasks
Labels
bug Something isn't working

Comments

@suspiciousRaccoon
Copy link

Description

hi! /ᐠ. ̫ .ᐟ\ฅ

A pydantic model with a EmailStr field raises polyfactory.exceptions.ParameterException: received constraints for unsupported type <class 'pydantic.networks.EmailStr'> if used with Field constraints.

related: #616

URL to code causing the issue

No response

MCVE

from polyfactory.factories.pydantic_factory import ModelFactory
from pydantic import BaseModel, EmailStr, Field

class Email(BaseModel):
    email: EmailStr = Field(max_length=20)

class EmailFactory(ModelFactory[Email]): ...

def test_factory():
    email = EmailFactory.build()

test_factory()

Steps to reproduce

1. Copy and paste MCVE into a python file
2. Assuming pydantic and polyfactory are installed, execute the file
3. See error

Screenshots

"In the format of: ![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

Release Version

2.19.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)
@suspiciousRaccoon suspiciousRaccoon added the bug Something isn't working label Feb 7, 2025
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

1 participant