litestar-org / litestar-org/polyfactory

Enhancement: "Allow None Optionals" for a single field

Open
#655 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

### Summary

I have a single field which is marked as optional. Is there a way to indicate that it should always be generated by polyfactory?

### Basic Example

```
class AppointmentRequest(PydanticBaseModel):
doctor_email: EmailStr | None

class AppointmentRequestFactory(ModelFactory[AppointmentRequest]):
# doesn't work
doctor_email: EmailStr
```

### Drawbacks and Impact

_No response_

### Unresolved questions

_No response_

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 at the ModelFactory entry point and reproduce the AppointmentRequest example to inspect how optional fields are generated. The change is done when a single optional field can be configured to always receive a non-None generated value without changing the default behavior of other optional fields.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.