Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow_nums: standard interface for loading/dumping #4672

Closed
oliver-sanders opened this issue Feb 10, 2022 · 3 comments · Fixed by #4712
Closed

flow_nums: standard interface for loading/dumping #4672

oliver-sanders opened this issue Feb 10, 2022 · 3 comments · Fixed by #4712
Assignees
Labels
bug? Not sure if this is a bug or not small
Milestone

Comments

@oliver-sanders
Copy link
Member

The flow_nums define the flows to which a task belongs.

Context:

  • Under normal conditions flow_nums = {1} # task belongs to the original flow.
  • Reflow tasks differ flow_nums = {2} # task belongs to a new flow.
  • When flows merge their numbers merge flow_nums = {1, 2} # flows 1 & 2 merged.
  • Triggered tasks are special cases flow_nums = {}.

Because flow_nums are a set order is not guaranteed. Consequently we should take care to serialise / deserialise flow_nums via a standard interface to ensure they always match.

Suggest the following:

def serialise(flow_nums):
   return json.dumps(sorted(flow_nums))

def unserialise(flow_num_str):
    set(json.loads(flow_num_str))

def db_serialise(flow_nums):
    return sorted(flow_nums)

If we don't sort the nums there is a risk that they could come out in a different order than they went in e.g. {2, 1} rather than {1, 2} which would break some internal comparison logic as well as making life harder for the UIs which would prefer one canonical form for each set.

Pull requests welcome!

@oliver-sanders oliver-sanders added bug? Not sure if this is a bug or not small labels Feb 10, 2022
@oliver-sanders oliver-sanders added this to the cylc-8.0rc2 milestone Feb 10, 2022
@hjoliver
Copy link
Member

This won't hurt, but I'm not sure it's necessary - any comparison logic ought to take account of the fact that it's comparing (unordered) sets, no?

@oliver-sanders
Copy link
Member Author

oliver-sanders commented Feb 11, 2022

This won't hurt, but I'm not sure it's necessary - any comparison logic ought to take account of the fact that it's comparing (unordered) sets, no?

If they are in set form, yes, however, if they are serialised, no, e.g:

#4581 (comment)

It's the read/write to the DB and data-store where this matters not inside the task pool (where set comparisons work great).

@hjoliver
Copy link
Member

Ok, duh. Got it 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug? Not sure if this is a bug or not small
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants