diff --git a/src/sentry/runner/commands/configoptions.py b/src/sentry/runner/commands/configoptions.py index 86ee6964c04740..aa3711e91362ae 100644 --- a/src/sentry/runner/commands/configoptions.py +++ b/src/sentry/runner/commands/configoptions.py @@ -37,7 +37,7 @@ def _attempt_update( last_update_channel = options.get_last_update_channel(key) if db_value == value: # This script is making changes with UpdateChannel.AUTOMATOR - # channel. Thus, if the laast update channel was already + # channel. Thus, if the last 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 last_update_channel is None: @@ -273,11 +273,18 @@ def sync(ctx: click.Context) -> None: ) presenter_delegator.flush() raise - presenter_delegator.unset(opt.name) else: - presenter_delegator.drift(opt.name, "") - drift_found = True + if ( + options.can_update( + opt.name, options.get(opt.name), options.UpdateChannel.AUTOMATOR + ) + == options.NotWritableReason.OPTION_ON_DISK + ): + continue + else: + presenter_delegator.drift(opt.name, options.get(opt.name)) + drift_found = True if invalid_options: status = "update_failed" diff --git a/tests/sentry/runner/commands/badsync.yaml b/tests/sentry/runner/commands/badsync.yaml new file mode 100644 index 00000000000000..67e2ab76dc78ef --- /dev/null +++ b/tests/sentry/runner/commands/badsync.yaml @@ -0,0 +1,2 @@ +options: + set_on_disk_option: 'hello' diff --git a/tests/sentry/runner/commands/test_configoptions.py b/tests/sentry/runner/commands/test_configoptions.py index c3ba7eeb52e2d8..5ce2c6d1fcf0ec 100644 --- a/tests/sentry/runner/commands/test_configoptions.py +++ b/tests/sentry/runner/commands/test_configoptions.py @@ -2,9 +2,15 @@ from pathlib import Path import pytest +from django.conf import settings from sentry import options -from sentry.options.manager import FLAG_AUTOMATOR_MODIFIABLE, FLAG_IMMUTABLE, UpdateChannel +from sentry.options.manager import ( + FLAG_AUTOMATOR_MODIFIABLE, + FLAG_IMMUTABLE, + FLAG_PRIORITIZE_DISK, + UpdateChannel, +) from sentry.runner.commands.configoptions import configoptions from sentry.runner.commands.presenters.consolepresenter import ConsolePresenter from sentry.testutils.cases import CliTestCase @@ -24,6 +30,12 @@ def register_options(self) -> Generator[None, None, None]: options.register("change_channel_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE) options.register("to_unset_option", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE) options.register("invalid_type", default=15, flags=FLAG_AUTOMATOR_MODIFIABLE) + options.register( + "set_on_disk_option", + default="", + flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE, + ) + settings.SENTRY_OPTIONS["set_on_disk_option"] = "test" yield @@ -36,6 +48,8 @@ def register_options(self) -> Generator[None, None, None]: options.unregister("change_channel_option") options.unregister("to_unset_option") options.unregister("invalid_type") + options.unregister("set_on_disk_option") + del settings.SENTRY_OPTIONS["set_on_disk_option"] @pytest.fixture(autouse=True) def set_options(self) -> None: @@ -184,6 +198,16 @@ def test_sync(self): assert not options.isset("to_unset_option") + def test_bad_sync(self): + rv = self.invoke( + "-f", + "tests/sentry/runner/commands/badsync.yaml", + "sync", + ) + assert rv.exit_code == 2, rv.output + + assert ConsolePresenter.ERROR_MSG % ("set_on_disk_option", "option_on_disk") in rv.output + def test_bad_patch(self): rv = self.invoke( "--file=tests/sentry/runner/commands/badpatch.yaml",