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

Switch Settings.dig to dot notation #19099

Merged
merged 3 commits into from
Nov 1, 2024
Merged

Conversation

stevenjcumming
Copy link
Contributor

Summary

  • Most settings are accessed via dot notation (Settings.parent_key.child_key)
  • Using .dig can obscure the use of those keys by making them difficult to find
  • The dot notation makes them easier to find
  • If dot notation isn't possible, dig is acceptable

Related issue(s)

  • n/a

Testing done

  • n/a

Acceptance criteria

  • Settings.dig is only used where dot notation isn't possible or difficult

@rmtolmach
Copy link
Contributor

Wow, I just came across this today in #18887 so I asked the PR author to change it up 🎉

@jerekshoe
Copy link
Contributor

Maybe this is a silly question, but isn’t the use of dig in most of these to avoid errors if any of the intermediate values is nil?

@shaunburdick
Copy link
Contributor

Maybe this is a silly question, but isn’t the use of dig in most of these to avoid errors if any of the intermediate values is nil?

I agree with @jerekshoe on this. If we want to mandate/restrict the use of .dig() perhaps put out a message and/or a ticket for each team so we can validate if the .dig is needed or not.

@va-vfs-bot va-vfs-bot temporarily deployed to sjc-remove-settings-dig/main/main October 25, 2024 22:08 Inactive
@jerekshoe
Copy link
Contributor

Maybe this is a silly question, but isn’t the use of dig in most of these to avoid errors if any of the intermediate values is nil?

I agree with @jerekshoe on this. If we want to mandate/restrict the use of .dig() perhaps put out a message and/or a ticket for each team so we can validate if the .dig is needed or not.

After thinking about this more I’m assuming it should be safe to use dot notation for these because they are updating usages of dig on the Settings hash, so if any of the intermediate values are nil there are probably bigger issues. I wasn’t thinking about this being scoped to the Settings hash when I asked my initial question

@stevenjcumming
Copy link
Contributor Author

@jerekshoe @shaunburdick My opinion is the default in the context of Settings should be dot notation, and if that's not possible dig is fine. If a parent (intermediate) key might be nil there's two ways to go about it.

  1. safe navigation with &
  2. dig

I think either are acceptable alternatives. Based on what I saw in the helm charts those values can't be nil and the settings that don't exist like modules_appeals_api.enabled_unsafe_mode return nil anyways

@va-vfs-bot va-vfs-bot temporarily deployed to sjc-remove-settings-dig/main/main October 28, 2024 22:45 Inactive
shaunburdick
shaunburdick previously approved these changes Oct 29, 2024
Copy link
Contributor

@shaunburdick shaunburdick left a comment

Choose a reason for hiding this comment

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

LGTM based on @stevenjcumming commment! 👍

Copy link
Contributor

@rmtolmach rmtolmach left a comment

Choose a reason for hiding this comment

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

Overall I like this! I found a few issues with some of the settings though.

@@ -64,7 +64,7 @@ def token_validation_result
private

def unsafe_mode?
Rails.env.development? && Settings.dig(:modules_appeals_api, :enable_unsafe_mode)
Rails.env.development? && Settings.modules_appeals_api.enable_unsafe_mode
Copy link
Contributor

Choose a reason for hiding this comment

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

@department-of-veterans-affairs/lighthouse-banana-peels This setting doesn't actually exist anywhere... It's not in settings.yml or in any of the values.yaml in the manifest repo.

@stevenjcumming
Copy link
Contributor Author

@rmtolmach I've add

pension_ipf_vanotify_status_callback and nod_vanotify_status_callback bearer_tokens to settings.yml

@va-vfs-bot va-vfs-bot temporarily deployed to sjc-remove-settings-dig/main/main October 31, 2024 22:50 Inactive
@stevenjcumming stevenjcumming merged commit 4924b69 into master Nov 1, 2024
26 checks passed
@stevenjcumming stevenjcumming deleted the sjc-remove-settings-dig branch November 1, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants