marshmallow
marshmallow copied to clipboard
load_only and dump_only validation
I was wondering if you would want some additional validation on this. I can put up a quick pull request if you like.
In schema.py, dump_only
and load_only
could be validated in the same way only
and exclude
are.
I ran into a scenario where I had something like MySchema(partial=True,dump_only=('name'))
(note the missing comma at the end of the tuple. This passes in the string name
and in the Marshmallow code, gets turned into a set. set(['a', 'e', 'm', 'n'])
This happens silently. I could add the same validators that only
and exclude
use.
Thoughts?
No objection.
Could this be considered a breaking change? (Would a user actually pass "abcde" to exclude fields "a", "b", "c", "d", and "e"?)
After a quick look, it appears to me again we need to harmonize how parameters are passed (#1244). only
and exclude
are treated differently. Some checks run if passed in Meta but not at init.
It doesn't seem likely to me that someone would pass a string expecting it to be chopped up into characters. The most likely thing to break for people would be if they had it silently failing, now it wouldn't be silent anymore alerting them to a bug in their code.
The docs look like they are expected to be similar. (Union[Sequence[str], Set[str]]
):
class marshmallow.Schema(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)[source]