Skip to content

Commit b8e9b1a

Browse files
committed
Merge branch '2.x-line' into dev
2 parents a0423c0 + 2888e69 commit b8e9b1a

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Deprecation/Removals:
3838
- Remove ``func`` parameter of ``fields.Function``. Remove ``method_name`` parameter of ``fields.Method`` (issue:`325`). Use the ``serialize`` parameter instead.
3939
- Remove ``extra`` parameter from ``Schema``. Use a ``@post_dump`` method to add additional data.
4040

41+
2.13.3 (2017-03-11)
42+
+++++++++++++++++++
43+
44+
Bug fixes:
45+
46+
- Restore backwards-compatibility of ``SchemaOpts`` constructor (:issue:`597`). Thanks :user:`Wesmania` for reporting and thanks :user:`frol` for the fix.
47+
4148
2.13.2 (2017-03-10)
4249
+++++++++++++++++++
4350

marshmallow/schema.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def __new__(mcs, name, bases, attrs):
100100
meta = getattr(klass, 'Meta')
101101
# Set klass.opts in __new__ rather than __init__ so that it is accessible in
102102
# get_declared_fields
103-
klass.opts = klass.OPTIONS_CLASS(meta, ordered=ordered)
103+
klass.opts = klass.OPTIONS_CLASS(meta)
104+
# Pass the inherited `ordered` into opts
105+
klass.opts.ordered = ordered
104106
# Add fields specifid in the `include` class Meta option
105107
cls_fields += list(klass.opts.include.items())
106108

@@ -177,7 +179,7 @@ def _resolve_processors(self):
177179
class SchemaOpts(object):
178180
"""class Meta options for the :class:`Schema`. Defines defaults."""
179181

180-
def __init__(self, meta, ordered=False):
182+
def __init__(self, meta):
181183
self.fields = getattr(meta, 'fields', ())
182184
if not isinstance(self.fields, (list, tuple)):
183185
raise ValueError("`fields` option must be a list or tuple.")
@@ -199,7 +201,7 @@ def __init__(self, meta, ordered=False):
199201
'Schema.dump will be excluded from the serialized output by default.',
200202
UserWarning
201203
)
202-
self.ordered = getattr(meta, 'ordered', ordered)
204+
self.ordered = getattr(meta, 'ordered', False)
203205
self.index_errors = getattr(meta, 'index_errors', True)
204206
self.include = getattr(meta, 'include', {})
205207
self.load_only = getattr(meta, 'load_only', ())

tests/test_options.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from marshmallow import fields, Schema
6+
from marshmallow import fields, Schema, SchemaOpts
77
from marshmallow.exceptions import ValidationError
88

99
from tests.base import * # noqa
@@ -228,3 +228,18 @@ class AddFieldsChild(self.AddFieldsSchema):
228228
assert 'email' in s._declared_fields.keys()
229229
assert 'from' in s._declared_fields.keys()
230230
assert isinstance(s._declared_fields['from'], fields.Str)
231+
232+
233+
class CustomSchemaOpts(SchemaOpts):
234+
def __init__(self, meta):
235+
super(CustomSchemaOpts, self).__init__(meta)
236+
self.custom_option = True
237+
238+
class SchemaWithCustomSchemaOpts(Schema):
239+
OPTIONS_CLASS = CustomSchemaOpts
240+
241+
class TestSchemaOptsClass:
242+
243+
def test_schema_with_custom_schema_opts(self):
244+
s = SchemaWithCustomSchemaOpts()
245+
assert s.opts.custom_option

0 commit comments

Comments
 (0)