litestar-org / litestar-org/polyfactory

Bug: ModelFactory doesn't support pydantic EmailStr Field constraints

Open
#642 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.5k
Forks
120
PR merge metrics
No merged PRs in 30d

Description

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: https://github.com/litestar-org/polyfactory/discussions/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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided MCVE and the ModelFactory entry point, then reproduce the EmailStr Field(max_length=20) failure using the listed steps. Trace how constraints are handled for Pydantic fields and add coverage for this case; done means EmailFactory.build() succeeds without the unsupported-type ParameterException.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.