@@ -35,22 +35,22 @@ def update_or_set_grouping_config_if_needed(project: Project, source: str) -> st
3535 use by scripts.
3636 """
3737 current_config = project .get_option ("sentry:grouping_config" )
38+ current_config_is_valid = current_config in GROUPING_CONFIG_CLASSES .keys ()
39+
40+ # If the project's current config comes back as the default one, it might be because that's
41+ # actually what's set in the database for that project, or it might be relying on the default
42+ # value of that project option. In the latter case, we can use this upgrade check as a chance to
43+ # set it. (We want projects to have their own record of the config they're using, so that when
44+ # we introduce a new one, we know to transition them.)
45+ project_option_exists = ProjectOption .objects .filter (
46+ key = "sentry:grouping_config" , project_id = project .id
47+ ).exists ()
3848
3949 if current_config == BETA_GROUPING_CONFIG :
4050 return "skipped - beta config"
4151
42- if current_config == DEFAULT_GROUPING_CONFIG :
43- # If the project's current config comes back as the default one, it might be because that's
44- # actually what's set in the database for that project, or it might be relying on the
45- # default value of that project option. In the latter case, we can use this upgrade check as
46- # a chance to set it. (We want projects to have their own record of the config they're
47- # using, so that when we introduce a new one, we know to transition them.)
48- project_option_exists = ProjectOption .objects .filter (
49- key = "sentry:grouping_config" , project_id = project .id
50- ).exists ()
51-
52- if project_option_exists :
53- return "skipped - up-to-date record exists"
52+ if current_config == DEFAULT_GROUPING_CONFIG and project_option_exists :
53+ return "skipped - up-to-date record exists"
5454
5555 # We want to try to write the audit log entry and project option change just once, so we use a
5656 # cache key to avoid raciness. It's not perfect, but it reduces the risk significantly.
@@ -69,10 +69,7 @@ def update_or_set_grouping_config_if_needed(project: Project, source: str) -> st
6969 changes : dict [str , str | int ] = {"sentry:grouping_config" : DEFAULT_GROUPING_CONFIG }
7070
7171 # If the current config is out of date but still valid, start a transition period
72- if (
73- current_config != DEFAULT_GROUPING_CONFIG
74- and current_config in GROUPING_CONFIG_CLASSES .keys ()
75- ):
72+ if current_config != DEFAULT_GROUPING_CONFIG and current_config_is_valid :
7673 # This is when we will stop calculating the old hash in cases where we don't find the
7774 # new hash (which we do in an effort to preserve group continuity).
7875 transition_expiry = (
@@ -86,10 +83,6 @@ def update_or_set_grouping_config_if_needed(project: Project, source: str) -> st
8683 }
8784 )
8885
89- project_option_exists = ProjectOption .objects .filter (
90- key = "sentry:grouping_config" , project_id = project .id
91- ).exists ()
92-
9386 for key , value in changes .items ():
9487 project .update_option (key , value )
9588
0 commit comments