Skip to content

fix: intersect OneOf and Equal choices in field2choices - #1069

Open
l46983284-cpu wants to merge 1 commit into
marshmallow-code:devfrom
l46983284-cpu:fix-198-field2choices-intersection
Open

fix: intersect OneOf and Equal choices in field2choices#1069
l46983284-cpu wants to merge 1 commit into
marshmallow-code:devfrom
l46983284-cpu:fix-198-field2choices-intersection

Conversation

@l46983284-cpu

Copy link
Copy Markdown

Fixes #198

When multiple choice validators are defined on a field (such as multiple validate.OneOf, multiple validate.Equal, or a mix of OneOf and Equal), the allowed choices should be the intersection of the values allowed by each validator.

Previously:

  • validate.Equal overrode any preceding validate.OneOf choices.
  • Multiple validate.Equal validators concatenated their values rather than intersecting them.

Changes

  • Treat validate.Equal comparable values as single-element choice sets and intersect all choice sets via OrderedSet.
  • Added unit tests for multiple OneOf, OneOf + Equal, and multiple Equal validators (both intersecting and non-intersecting).

…llow-code#198)

Calculate intersection across all choice validators (both validate.OneOf and
validate.Equal) present on field.validators.

Signed-off-by: Alex Chen <l46983284@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minor issues with field2choices

1 participant