Skip to content

OneOf.options() emits extra pairs when labels outnumber choices #2869

@T90REAL

Description

@T90REAL

marshmallow.validate.OneOf.options() is supposed to “return the (value, label) pairs, where value is a string associated with each choice.” However the implementation zips choices and labels with zip_longest(..., fillvalue=""), so it produces as many pairs as the longer input. When labels is longer than choices, options() yields phantom entries whose value is the empty string, even though no such choice exists.
Better to raise a ValueErorr?

from marshmallow.validate import OneOf

oneof = OneOf(choices=[], labels=["extra"])
print(list(oneof.options()))
# Expected: []
# Actual: [('', 'extra')]  # bogus option with empty string value

Note: This issue was identified by an automated testing tool for academic research and manually verified. If you have any concerns about this type of reporting, please let me know, and I will adjust my workflow accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions