Skip to content

Support MutableMapping and MutableSequence container traversal in JsonDataConverter and type discovery #352

Open

Description

Description

While JsonDataConverter.can_reconstruct() and _coerce_generic() in durabletask/serialization.py support dict / Mapping, tuple, and list / Sequence containers, they currently omit collections.abc.MutableMapping and collections.abc.MutableSequence.

Because typing.get_origin() resolves MutableMapping[str, Model] to collections.abc.MutableMapping and MutableSequence[Model] to collections.abc.MutableSequence, can_reconstruct() returns False for these annotations:

conv = JsonDataConverter()
conv.can_reconstruct(MutableMapping[str, MyModel])  # returns False
conv.can_reconstruct(MutableSequence[MyModel])      # returns False

As a consequence:

  1. Inbound type discovery in type_discovery.activity_input_type() and orchestrator_input_type() ignores these parameter annotations and returns None. Activities and orchestrators receiving input payloads annotated as MutableMapping or MutableSequence receive raw dicts and lists rather than coerced model instances.
  2. Direct deserialization via converter.deserialize(payload, target_type=MutableMapping[str, MyModel]) leaves the inner values uncoerced.

Expected Behavior

JsonDataConverter.can_reconstruct() should recognize MutableMapping and MutableSequence annotations when their value/element types are reconstructable. In addition, _coerce_generic() should recursively coerce items for MutableMapping and MutableSequence container types.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions