Skip to content

Commit 36bbe89

Browse files
author
Matias Melograno
committed
improvements on validating properties
1 parent a9e89da commit 36bbe89

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

splitio/client/input_validator.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,12 @@ def valid_properties(properties):
485485
_LOGGER.error('track: properties must be of type dictionary.')
486486
return False, None, 0
487487

488-
valid_properties = None
488+
valid_properties = dict()
489489

490490
for property, element in properties.items():
491491
if not isinstance(property, six.string_types): # Exclude property if is not string
492492
continue
493493

494-
if valid_properties is None:
495-
valid_properties = dict()
496-
497494
valid_properties[property] = None
498495
size += len(property)
499496

@@ -517,7 +514,7 @@ def valid_properties(properties):
517514
)
518515
return False, None, size
519516

520-
if isinstance(valid_properties, dict) and len(valid_properties.keys()) > 300:
517+
if len(valid_properties.keys()) > 300:
521518
_LOGGER.warning('Event has more than 300 properties. Some of them will be trimmed' +
522519
' when processed')
523-
return True, valid_properties, size
520+
return True, valid_properties if len(valid_properties.keys()) > 0 else None, size

tests/client/test_input_validator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,14 @@ def test_valid_properties(self, mocker):
451451
assert input_validator.valid_properties(None) == (True, None, 1024)
452452
assert input_validator.valid_properties([]) == (False, None, 0)
453453
assert input_validator.valid_properties(True) == (False, None, 0)
454-
454+
assert input_validator.valid_properties(dict()) == (True, None, 1024)
455+
assert input_validator.valid_properties({ 2: 123 }) == (True, None, 1024)
456+
457+
class Test:
458+
pass
459+
assert input_validator.valid_properties({
460+
"test": Test()
461+
}) == (True, { "test": None }, 1028)
455462

456463
props1 = {
457464
"test1": "test",

0 commit comments

Comments
 (0)