Browse Source

fix(options) Change the log message when we try to set an option to the default value. (#50689)

Most times we would not set an option (that is not set in the DB) to the
default value as per option definition.

There is a valid scenario though:
- I want to change the default value
- But I do not want to change the current production behavior 
- SO I would set the option in the DB to the current default value 
- Then I would change the default itself in code.

Before this PR, this behavior would have been ok but the log message was
the same we use when we change the last update channel. This fixes the
log message.

Co-authored-by: Kyle Owens <owensk@gmail.com>
Filippo Pacifici 1 year ago
parent
commit
65dcc79bb5

+ 13 - 1
src/sentry/runner/commands/configoptions.py

@@ -30,7 +30,19 @@ def _attempt_update(key: str, value: Any, drifted_options: Set[str], dry_run: bo
         # channel. Thus, if the laast update channel was already
         # UpdateChannel.AUTOMATOR, and the value we are trying to set
         # is the same as the value already stored we do nothing.
-        if options.get_last_update_channel(key) != options.UpdateChannel.AUTOMATOR:
+        last_update_channel = options.get_last_update_channel(key)
+        if last_update_channel is None:
+            # Here we are trying to set an option with a value that
+            # is equal to its default. There are valid cases for this
+            # behavior: I plan to change the default value of an option
+            # without changing the production behavior. So I would
+            # first set the option to the current default value in
+            # the DB and then change the default value.
+            if not dry_run:
+                options.set(key, value, coerce=False, channel=options.UpdateChannel.AUTOMATOR)
+            click.echo(UPDATE_MSG % key)
+
+        elif last_update_channel != options.UpdateChannel.AUTOMATOR:
             if not dry_run:
                 options.set(key, value, coerce=False, channel=options.UpdateChannel.AUTOMATOR)
             click.echo(CHANNEL_UPDATE_MSG % key)

+ 1 - 1
tests/sentry/runner/commands/test_configoptions.py

@@ -23,7 +23,7 @@ class ConfigOptionsTest(CliTestCase):
         options.register("int_option", default=20, flags=FLAG_AUTOMATOR_MODIFIABLE)
         options.register("str_option", default="blabla", flags=FLAG_AUTOMATOR_MODIFIABLE)
         options.register("map_option", default={}, flags=FLAG_AUTOMATOR_MODIFIABLE)
-        options.register("list_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)
+        options.register("list_option", default=[1, 2], flags=FLAG_AUTOMATOR_MODIFIABLE)
         options.register("drifted_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)
         options.register("change_channel_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)
         options.register("to_unset_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)