Skip to content

TaggedJSONSerializer does not preserve int keys in dicts #1908

@ThiefMaster

Description

@ThiefMaster

The TaggedJSONSerializer used for session serialization is rather smart when it comes to preserving types that usually cannot be JSON-encoded. However, it still has the problem that dict keys are converted to strings.

>>> from flask.sessions import TaggedJSONSerializer
>>> tj = TaggedJSONSerializer()
>>> tj.loads(tj.dumps({123: u'blah'}))
{u'123': u'blah'}

I think it would make sense to also tag the key here:

elif isinstance(value, dict):
    return dict((k, _tag(v)) for k, v in iteritems(value))

The one drawback I see is that there could be code relying on the implicit conversion right now..

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions