Fix marshmallow type subclass check #102
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @fuhrysteve ! #81 along with #86 introduced a bug that causes builds to fail. This PR fixes it.
What happened
#81 added sequential subclass check that iterated over the mapping from marshmallow types to python types. #86 added
fields.Number
as a key anddecimal.Decimal
as a corresponding value. Since only Python 3.6 introduced ordered dictionaries, in previous versions order was not guaranteed.This means that sometimes the keys in that dictionary were ordered in such a way that
fields.Number
came first. That meant that python type corresponding tofields.Integer
becamedecimal.Decimal
and notint
as expected. As JSON schema output forDecimal
andint
differs too, that lead to failing tests.How it was fixed
Instead of dict I iterate over a tuple of tuples - this will guarantee the order of subclass checks. I also reworked the mapping and handcrafted it into the library so that we don't depend on what the order was in marshmallow
TYPE_MAPPING
dictionary: note that we couldn't, for example, reason about corresponding Python type forfields.Raw
as it could be eitherlist
,set
ortuple
.