Skip to content

Conversation

netsettler
Copy link
Contributor

The main purposes of this PR are these:

  • Fix a bug in the defaulting of the indexer value in the main program, which was defaulting to False (which in turn hides the environment value of True that was trying to get through). I changed the default to None from False. The logic to turn an unspecified value to False happens elsewhere already.

  • Add an accessor dcicutils.deployment_utils.boolean_setting which can be used to recover a boolean from settings that have "true" and "false" values floating around.

  • Added unit tests.

Opportunistic:

  • I added some function documention some of the new lang_utils functions and changed relative_time_string to allow it to take a datetime.timedelta as an argument. (It's easier to see such needs when writing doc.)

…loyment_utils.boolean_setting helper function. Document some of the new lang functions. Add some unit tests.
@netsettler netsettler requested a review from willronchetti May 4, 2020 17:13
@coveralls
Copy link

coveralls commented May 4, 2020

Pull Request Test Coverage Report for Build 994

  • 19 of 19 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.2%) to 68.513%

Totals Coverage Status
Change from base Build 987: 1.2%
Covered Lines: 1373
Relevant Lines: 2004

💛 - Coveralls

Copy link
Member

@willronchetti willronchetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with a few small comments.

default=False)
help="whether this server does indexing at all",
choices=["true", "false"],
default=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is None really what we want here? Will it pick up a default option elsewhere? Same question for --index_server, I think default should be False in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the problem is that we either have to have a rule that the command arguments override the environment variables or vice versa. The rule was (and I guess I could change this because it isn't clear it's right) that the arguments override the env variables, and so putting False here made the env variables not work. But anyway there is logic that picks up the env variables and defaults it. (This is all heavily unit tested but could still have gone by you as even then it's subtle.)

Another complexity in the design space is that env variables are strings and command arguments can be real datatypes. That's weird because when the env variables are merged, you also have to do various kinds of coercions to even get them on a level playing field, and THEN you have to flatten them again to strings to put them in an ini file and AGAIN recover them as strings later. I REALLY wish we were using a json structure to hold this data so we didn't have to do that second coerce-to-string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving this alone for now.

def test_deployment_utils_main():

fake_template = "something.ini"
with override_environ(ENV_NAME='fourfront-foo'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test could use some documentation I'd say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Will add.

return True
else:
return setting
else: # booleans, None, and odd types (though we might want to consider making other types an error).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not coerce None into False?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since None is already a false value, I thought it might be better to leave it as None in case we have to debug the difference between an explicit value and no value. I could change that if you thought it wise ,but my sense was it was better to leave the thin distinction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that's a good point, so let's keep it.

elif setting_lower == "true":
return True
else:
return setting
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not coerce whatever this could be to False?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, it already functions as a false value. I really wanted to raise an error here, but was nervous about where that error would be perceived. Returning a stray value might make it easier to spot the error downstream than if we coerce it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again seems reasonable.

@netsettler netsettler merged commit 5ff988e into master May 5, 2020
@netsettler netsettler deleted the kmp_misc_clarifications branch May 11, 2020 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants