python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

feat: fix dump one of fields

Open aymen-k opened this issue 1 year ago • 2 comments

Summary

Hey 👋 I generated code with pydantic validation. A nested class failed the validation. For some reason, the object is validated twice once with the initialized object and once with empty fields.

    @model_validator(mode="after")
    def check_oneof(cls, values):
        return cls._validate_field_groups(values)

Switching the order of the condition made it possible to avoid the second 'extra' validation.

Checklist

  • [x] If code changes were made then they have been tested.
    • [ ] I have updated the documentation to reflect the changes.
  • [x] This PR fixes an issue.
  • [ ] This PR adds something new (e.g. new method or parameters).
    • [ ] This change has an associated test.
  • [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • [ ] This PR is not a code change (e.g. documentation, README, ...)

aymen-k avatar Dec 19 '24 14:12 aymen-k

Hi there, what does this fix? Please can you add a regression test

Gobot1234 avatar Dec 19 '24 14:12 Gobot1234

Hi @Gobot1234, just added description to the PR

aymen-k avatar Dec 19 '24 15:12 aymen-k