The indexer stores event payloads with unknown = INCLUDE so that attributes we do not model yet are kept as they arrive. Attribute names such as token.symbol do not survive: the key is split at the dot and the value ends…
The indexer stores event payloads with unknown = INCLUDE so that attributes we do not model yet are kept as they arrive. Attribute names such as token.symbol do not survive: the key is split at the dot and the value ends up inside a nested dict. When the first part is also the name of a declared field, loading crashes.
from marshmallow import INCLUDE, Schema, fields
class EventSchema(Schema):
class Meta:
unknown = INCLUDE
foo = fields.Str()
EventSchema().load({"foo": "hi", "alpha.beta": "woah!"})
EventSchema().load({"foo": "hi", "foo.bar": 1})
{"foo": "hi", "alpha.beta": "woah!"}
{"foo": "hi", "foo.bar": 1}
{'foo': 'hi', 'alpha': {'beta': 'woah!'}}
ValueError: Cannot set foo.bar in foo due to existing value: hi
unknown=INCLUDE are copied to the result unchanged, whether the option comes from Meta, from load(..., unknown=INCLUDE) or from a Nested field.attribute, as in fields.Str(attribute="address.city"), still writes into a nested dict, and a dotted data_key is still just a key.Adapted from marshmallow-code/marshmallow (MIT).
Visible test command
pytest testsThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
unknown-dotted-keys-become-nested
Changes under src/ are evaluated.