Skip to content

Think if ops.Relation.save could sort collections #2391

@dimaqq

Description

@dimaqq

Totally out-of-the-box thinking task:

Spec:
The charm library must emit collections in a Comment start stable order Comment end , to avoid bounce in the relation data.

Note that a stable order always exists in JSON, because each object has a string representation, which could be

Leon Mintz
Is it practical to have ops .save do the sorting automatically?

Dima Tisnek
No, not in the general case, because the hypothetical algorithm would have to go inside the user-defined data model, for example class Foo: foo: list[Bar] where Bar may not be comparable.
An argument can be made that JSON representation of Bar are strings and that could be sorted, but that would require the algorithm to find all collections, incl nested, serialise their elements, sort, then wrap in a collection [...].
I'll think about that as a possible helper/metaclass/something!

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