marshmallow-code / marshmallow-code/marshmallow

Emit warning when user passes string instead of list to OneOf

Open
#2,074 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

I just got caught.

I wrote

```py
validate=validate.OneOf("one", "two")
```

instead of

```py
validate=validate.OneOf(["one", "two"])
```

`"one"` would pass because `"one" in "one"` is `True`.

It might save users trouble if we emitted a warning when a string is passed instead of a non-string iterable.

In practice, it only affects lists made of two elements (or one but users would use `Equal`), so no big deal.

Contributor guide

Open the contributing guide

Research direction

Start at the OneOf validator entry point and trace how its choices are accepted. Reproduce the string-versus-list case, then add coverage for the warning and confirm the existing list form remains valid; done means the misuse is warned about without changing normal iterable validation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.