art049 / art049/odmantic

Support typing.annotated

Open
#558 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
1.2k
Forks
97
PR merge metrics
No merged PRs in 30d

Description

# Feature request

### Context

This works:

```py
class ClassicMemberItem(Model):
id2: str = Field(default_factory=lambda: 'm1id')

m1 = ClassicMemberItem() # id=ObjectId('6a13e2017c4eef33beb24616') id2='m1id'
```

This does not work:

```py
from typing import Annotated

class ClassicMemberItem2(Model):
id2: Annotated[str, Field(default_factory=lambda: 'm2id')]

m2 = ClassicMemberItem2() # ValidationError: 1 validation error for ClassicMemberItem2
```

However, `typing.annotated` is supported by Pydantic.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two ClassicMemberItem examples and inspect how Model processes Field metadata from annotations. Compare the working assignment form with typing.Annotated handling, then verify that the Annotated form constructs successfully and applies the default_factory value without a validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.