Skip to content

Flags: String access, dict conversion, and deletion

Dan Guest requested to merge dguest/athena:flags into main

These changes allow you to dump the flags as a dictionary, which is useful to save them as a more standard data structure:

flag_dict = flags.something.asdict()
with open('something.json','w') as flagout:
    json.write(flag_dict, flagout)

Two more features: you can also use the [key] syntax to access flags by string, and you can delete flags1:

del flags.something['somethingElse']
flags['someting'].somethingElse = "newValue"

This [key] access seems a bit more friendly than the getattr(flags, key) syntax that appears in Athena a lot.

Deletion is probably more of a niche case, but better than the alternatives, which are:

  • Access the private member data for AthConfigFlags and delete the flags by hand
  • Something like
    flags.something['somethingElse_tmp'] = "newValue"
    flags = flags.cloneAndReplace('something.somethingElse', 'something.somethingElse_tmp')

Since it's possible to delete flags already, it seemed like we should be using obvious syntax.

MRs spawned by this one

I also marked the flags('Something.somethingElse') syntax as deprecated, because it seems pretty confusing and error prone to make flags callable.

[I created !65067 (merged) so that this MR doesn't cause our code to generate lots of deprecation warnings]

I also fixed a bug in the athHash() function: it was relying on the ordering of dictionaries.

[While implementing unit tests for the deletion I found a bug in our hash function implementation, see !65065 (merged) for the fix there. I've disabled the unit test for the hash because I was asked to remove the fix from this MR.]

  1. assuming the flags aren't locked

Edited by Dan Guest

Merge request reports