Skip to content

Updated localhostjson sync #574

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

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion splitio/sync/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ def _make_feature_flag(feature_flag_name, conditions, configs=None):
'defaultTreatment': 'control',
'algo': 2,
'conditions': conditions,
'configurations': configs
'configurations': configs,
'prerequisites': []
})

@staticmethod
Expand Down Expand Up @@ -542,6 +543,8 @@ def _sanitize_feature_flag_elements(self, parsed_feature_flags):
if 'sets' not in feature_flag:
feature_flag['sets'] = []
feature_flag['sets'] = validate_flag_sets(feature_flag['sets'], 'Localhost Validator')
if 'prerequisites' not in feature_flag:
feature_flag['prerequisites'] = []
sanitized_feature_flags.append(feature_flag)
return sanitized_feature_flags

Expand All @@ -560,6 +563,7 @@ def _sanitize_rb_segment_elements(self, parsed_rb_segments):
if 'name' not in rb_segment or rb_segment['name'].strip() == '':
_LOGGER.warning("A rule based segment in json file does not have (Name) or property is empty, skipping.")
continue

for element in [('trafficTypeName', 'user', None, None, None, None),
('status', splits.Status.ACTIVE.value, None, None, [e.value for e in splits.Status], None),
('changeNumber', 0, 0, None, None, None)]:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
rbsegments_json = [{"changeNumber": 12, "name": "some_segment", "status": "ACTIVE","trafficTypeName": "user","excluded":{"keys":[],"segments":[]},"conditions": []}]

split11 = {"ff": {"t": 1675443569027, "s": -1, "d": [
{"trafficTypeName": "user", "name": "SPLIT_2","trafficAllocation": 100,"trafficAllocationSeed": 1057590779, "seed": -113875324, "status": "ACTIVE","killed": False, "defaultTreatment": "off", "changeNumber": 1675443569027,"algo": 2, "configurations": {},"conditions": [{"conditionType": "ROLLOUT","matcherGroup": {"combiner": "AND","matchers": [{"keySelector": { "trafficType": "user", "attribute": None },"matcherType": "ALL_KEYS","negate": False,"userDefinedSegmentMatcherData": None,"whitelistMatcherData": None,"unaryNumericMatcherData": None,"betweenMatcherData": None,"booleanMatcherData": None,"dependencyMatcherData": None,"stringMatcherData": None}]},"partitions": [{ "treatment": "on", "size": 100 },{ "treatment": "off", "size": 0 }],"label": "default rule"}], "sets": ["set_1"], "impressionsDisabled": False},
{"trafficTypeName": "user", "name": "SPLIT_2","trafficAllocation": 100,"trafficAllocationSeed": 1057590779, "seed": -113875324, "status": "ACTIVE","killed": False, "defaultTreatment": "off", "changeNumber": 1675443569027,"algo": 2, "configurations": {},"conditions": [{"conditionType": "ROLLOUT","matcherGroup": {"combiner": "AND","matchers": [{"keySelector": { "trafficType": "user", "attribute": None },"matcherType": "ALL_KEYS","negate": False,"userDefinedSegmentMatcherData": None,"whitelistMatcherData": None,"unaryNumericMatcherData": None,"betweenMatcherData": None,"booleanMatcherData": None,"dependencyMatcherData": None,"stringMatcherData": None}]},"partitions": [{ "treatment": "on", "size": 100 },{ "treatment": "off", "size": 0 }],"label": "default rule"}], "sets": ["set_1"], "impressionsDisabled": False, 'prerequisites': []},
{"trafficTypeName": "user", "name": "SPLIT_1", "trafficAllocation": 100, "trafficAllocationSeed": -1780071202,"seed": -1442762199, "status": "ACTIVE","killed": False, "defaultTreatment": "off", "changeNumber": 1675443537882,"algo": 2, "configurations": {},"conditions": [{"conditionType": "ROLLOUT", "matcherGroup": {"combiner": "AND","matchers": [{"keySelector": { "trafficType": "user", "attribute": None },"matcherType": "ALL_KEYS","negate": False,"userDefinedSegmentMatcherData": None,"whitelistMatcherData": None,"unaryNumericMatcherData": None,"betweenMatcherData": None,"booleanMatcherData": None,"dependencyMatcherData": None,"stringMatcherData": None}]},"partitions": [{ "treatment": "on", "size": 0 },{ "treatment": "off", "size": 100 }],"label": "default rule"}], "sets": ["set_1", "set_2"]},
{"trafficTypeName": "user", "name": "SPLIT_3","trafficAllocation": 100,"trafficAllocationSeed": 1057590779, "seed": -113875324, "status": "ACTIVE","killed": False, "defaultTreatment": "off", "changeNumber": 1675443569027,"algo": 2, "configurations": {},"conditions": [{"conditionType": "ROLLOUT","matcherGroup": {"combiner": "AND","matchers": [{"keySelector": { "trafficType": "user", "attribute": None },"matcherType": "ALL_KEYS","negate": False,"userDefinedSegmentMatcherData": None,"whitelistMatcherData": None,"unaryNumericMatcherData": None,"betweenMatcherData": None,"booleanMatcherData": None,"dependencyMatcherData": None,"stringMatcherData": None}]},"partitions": [{ "treatment": "on", "size": 100 },{ "treatment": "off", "size": 0 }],"label": "default rule"}], "sets": ["set_1"], "impressionsDisabled": True}
]}, "rbs": {"t": -1, "s": -1, "d": rbsegments_json}}
Expand Down
4 changes: 4 additions & 0 deletions tests/sync/test_splits_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,10 @@ def test_elements_sanitization(self, mocker):
split[0]['algo'] = 1
assert (split_synchronizer._sanitize_feature_flag_elements(split)[0]['algo'] == 2)

split = splits_json["splitChange1_1"]['ff']['d'].copy()
del split[0]['prerequisites']
assert (split_synchronizer._sanitize_feature_flag_elements(split)[0]['prerequisites'] == [])

# test 'status' is set to ACTIVE when None
rbs = copy.deepcopy(json_body["rbs"]["d"])
rbs[0]['status'] = None
Expand Down