Skip to content

Empty Only Treated as None #772

@deckar01

Description

@deckar01

When the only parameter is an empty list/set, it causes all the fields to be de/serialized like None. The implementation of 2.x and 3.0 are not in compliance with their respective docs.

only (tuple) – A list or tuple of fields to serialize. If None, all fields will be serialized.

class TestSchema(Schema):
    foo = fields.Field()
sch = TestSchema(only=())
data = dict(foo='bar')
result = sch.dump(data)
assert 'foo' not in result

# assert 'foo' not in {'foo': 'bar'}

This could create a security vulnerability if an application was dynamically generating the field set based on security role. A filter that was meant to hide everything would inadvertently show everything.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions