diff -Naur marshmallow-2.11.1.orig/marshmallow/schema.py marshmallow-2.11.1/marshmallow/schema.py
--- marshmallow-2.11.1.orig/marshmallow/schema.py 2017-01-08 22:23:48.000000000 +0100
+++ marshmallow-2.11.1/marshmallow/schema.py 2018-09-21 14:20:06.756913165 +0200
@@ -324,7 +324,7 @@
"""
pass
- def __init__(self, extra=None, only=(), exclude=(), prefix='', strict=None,
+ def __init__(self, extra=None, only=None, exclude=(), prefix='', strict=None,
many=False, context=None, load_only=(), dump_only=(),
partial=False):
# copy declared fields from metaclass
@@ -692,7 +692,7 @@
def _normalize_nested_options(self):
"""Apply then flatten nested schema options"""
- if self.only:
+ if self.only is not None:
# Apply the only option to nested fields.
self.__apply_nested_option('only', self.only)
# Remove the child field names from the only option.
@@ -725,7 +725,7 @@
def _update_fields(self, obj=None, many=False):
"""Update fields based on the passed in object."""
- if self.only:
+ if self.only is not None:
# Return only fields specified in only option
if self.opts.fields:
field_names = self.set_class(self.opts.fields) & self.set_class(self.only)
diff -Naur marshmallow-2.11.1.orig/tests/test_schema.py marshmallow-2.11.1/tests/test_schema.py
--- marshmallow-2.11.1.orig/tests/test_schema.py 2017-01-08 22:23:48.000000000 +0100
+++ marshmallow-2.11.1/tests/test_schema.py 2018-09-21 14:20:06.758913124 +0200
@@ -884,6 +884,12 @@
sch = MySchema(only=('baz', ))
assert sch.dump({'foo': 42}).data == {}
+def test_only_empty():
+ class MySchema(Schema):
+ foo = fields.Field()
+
+ sch = MySchema(only=())
+ assert 'foo' not in sch.dump({'foo': 'bar'})
def test_nested_only_and_exclude():
class Inner(Schema):