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 and decimal.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 to fields.Integer became decimal.Decimal and not int as expected. As JSON schema output for Decimal and int 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 for fields.Raw as it could be either list, set or tuple.
Coverage remained the same at ?% when pulling 24799897dd09d0f38c09475499fff7fcdfb77d6f on atmo:fix_marshmallow_type_check into 3c579c7d3b9c579e8610f7e698d4589604d4884c on fuhrysteve:master.
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
.