<#2515 [BUG] Order of keys from DictTransformer is...
# flytekit
a
#2515 [BUG] Order of keys from DictTransformer is non-deterministic Issue created by ggydush-fn Describe the bug When using a dictionary with Flyte, the order of the keys is not deterministic. Python dictionary ordering is something that would be awesome to guarantee, as it was surprising to me when the order or the keys changed on Flyte. Expected behavior Maintain order of keys when using dictionaries on Flyte. Additional context to reproduce This example will fail. The
lit
and
transformed_lit
variables look identical, but are not after converting to Python value.
Copy code
import string
from flytekit.core.context_manager import FlyteContext
from flytekit.core.type_engine import DictTransformer, TypeEngine
from flytekit.models import literals

def simulate_dict_transform(data: dict, python_type: type) -> dict:
    t = DictTransformer()
    ctx = FlyteContext.current_context()
    lit = t.to_literal(ctx, data, python_type, TypeEngine.to_literal_type(python_type))
    transformed_lit = literals.Literal.from_flyte_idl(lit.to_flyte_idl())
    return t.to_python_value(ctx, transformed_lit, python_type)

data = {k: v for v, k in enumerate(string.ascii_lowercase)}
transformed = simulate_dict_transform(data, dict[str, int])
print(data.keys())
print(transformed.keys())
assert list(data.keys()) == list(transformed.keys())
Screenshots No response Are you sure this issue hasn't been raised already? ☑︎ Yes Have you read the Code of Conduct? ☑︎ Yes flyteorg/flyte