Skip to content

Commit d66ea5b

Browse files
authored
pre parse edge case patch (#415)
to prevent deleting unsupported spec twice which can cause key err panic
1 parent 9ebb7d9 commit d66ea5b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

statsig/spec_store.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def get_parsed_specs(key: str):
181181
return parsed
182182

183183
def parse_target_value_map_from_spec(spec, parsed):
184+
unsupported_specs = set()
184185
for rule in spec.get("rules", []):
185186
for i, cond in enumerate(rule.get("conditions", [])):
186187
op = cond.get("operator", None)
@@ -190,12 +191,12 @@ def parse_target_value_map_from_spec(spec, parsed):
190191
op = op.lower()
191192
if op not in Const.SUPPORTED_OPERATORS:
192193
self.unsupported_configs.add(spec.get("name"))
193-
del parsed[spec.get("name")]
194+
unsupported_specs.add(spec.get("name"))
194195
if cond_type is not None:
195196
cond_type = cond_type.lower()
196197
if cond_type not in Const.SUPPORTED_CONDITION_TYPES:
197198
self.unsupported_configs.add(spec.get("name"))
198-
del parsed[spec.get("name")]
199+
unsupported_specs.add(spec.get("name"))
199200

200201
if op in ("any", "none") and cond_type == "user_bucket":
201202
rule["conditions"][i]["user_bucket"] = {}
@@ -220,6 +221,9 @@ def parse_target_value_map_from_spec(spec, parsed):
220221
rule["conditions"][i]["fast_target_value"] = {}
221222
for val in target_value:
222223
rule["conditions"][i]["fast_target_value"][str(val)] = True
224+
for spec_name in unsupported_specs:
225+
if spec_name in parsed:
226+
del parsed[spec_name]
223227

224228
self.unsupported_configs.clear()
225229
new_gates = get_parsed_specs(EntityType.GATE.value)

0 commit comments

Comments
 (0)