team23 / pydantic-partial

Create partial models from pydantic models
MIT License
51 stars 8 forks source link

feat: add ignore_validators flag #28

Closed ADR-007 closed 6 months ago

ADR-007 commented 8 months ago

Take Annotated into account when ignore_validators=False

I believe this field ignore_validators should be False by default. This is a for this issue

class SomethingListWithAnnotatedMinItems(PartialModelMixin, pydantic.BaseModel):
    items: Annotated[list[Something], MinLen(1)]

Before:
# SomethingListWithAnnotatedMinItems.as_partial() -> items: Optional[ist[Something]]

Now:
# SomethingListWithAnnotatedMinItems.as_partial() -> items: Optional[Annotated[list[Something], MinLen(1)]]
ddanier commented 7 months ago

My initial feeling would be this is a great addition. Need to play with this a little bit :)

ddanier commented 6 months ago

@ADR-007 Sorry for the delayed reply.

I see two major issues with the PR:

I would argue that having this PR merged would only increase the confusion around validators at the moment. We need to have a complete solution handling those.

Would you be willing to extend the PR to also contain this?

ADR-007 commented 6 months ago

Thank you for that detailed code review!

It seems to be much easier in my case to support Pydantic v2 only, as I described it here. We can close this PR :)