Skip to content

Updated validation and model #584

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 3 commits into from
Jun 30, 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
15 changes: 7 additions & 8 deletions splitio/client/input_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def validate_factory_instantiation(sdk_key):
return True


def valid_properties(properties):
def valid_properties(properties, source):
"""
Check if properties is a valid dict and returns the properties
that will be sent to the track method, avoiding unexpected types.
Expand All @@ -580,7 +580,7 @@ def valid_properties(properties):
return True, None, size

if not isinstance(properties, dict):
_LOGGER.error('track: properties must be of type dictionary.')
_LOGGER.error('%s: properties must be of type dictionary.', source)
return False, None, 0

valid_properties = dict()
Expand All @@ -597,7 +597,7 @@ def valid_properties(properties):

if not isinstance(element, str) and not isinstance(element, Number) \
and not isinstance(element, bool):
_LOGGER.warning('Property %s is of invalid type. Setting value to None', element)
_LOGGER.warning('%s: Property %s is of invalid type. Setting value to None', source, element)
element = None

valid_properties[property] = element
Expand All @@ -607,14 +607,13 @@ def valid_properties(properties):

if size > MAX_PROPERTIES_LENGTH_BYTES:
_LOGGER.error(
'The maximum size allowed for the properties is 32768 bytes. ' +
'Current one is ' + str(size) + ' bytes. Event not queued'
)
'%s: The maximum size allowed for the properties is 32768 bytes. ' +
'Current one is ' + str(size) + ' bytes. Event not queued', source)
return False, None, size

if len(valid_properties.keys()) > 300:
_LOGGER.warning('Event has more than 300 properties. Some of them will be trimmed' +
' when processed')
_LOGGER.warning('%s: Event has more than 300 properties. Some of them will be trimmed' +
' when processed', source)
return True, valid_properties if len(valid_properties) else None, size

def validate_pluggable_adapter(config):
Expand Down
18 changes: 16 additions & 2 deletions splitio/engine/impressions/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ def process_impressions(self, impressions):
:returns: Tuple of to be stored, observed and counted impressions, and unique keys tuple
:rtype: list[tuple[splitio.models.impression.Impression, dict]], list[], list[], list[]
"""
imps = [(self._observer.test_and_set(imp), attrs) for imp, attrs in impressions]
imps = []
for imp, attrs in impressions:
if imp.properties is not None:
imps.append((imp, attrs))
continue

imps.append((self._observer.test_and_set(imp), attrs))

return [i for i, _ in imps], imps, [], []

class StrategyNoneMode(BaseStrategy):
Expand Down Expand Up @@ -85,7 +92,14 @@ def process_impressions(self, impressions):
:returns: Tuple of to be stored, observed and counted impressions, and unique keys tuple
:rtype: list[tuple[splitio.models.impression.Impression, dict]], list[splitio.models.impression.Impression], list[splitio.models.impression.Impression], list[]
"""
imps = [(self._observer.test_and_set(imp), attrs) for imp, attrs in impressions]
imps = []
for imp, attrs in impressions:
if imp.properties is not None:
imps.append((imp, attrs))
continue

imps.append((self._observer.test_and_set(imp), attrs))

counter_imps = [imp for imp, _ in imps if imp.previous_time != None]
this_hour = truncate_time(utctime_ms())
return [i for i, _ in imps if i.previous_time is None or i.previous_time < this_hour], imps, counter_imps, []
3 changes: 2 additions & 1 deletion splitio/models/impressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'change_number',
'bucketing_key',
'time',
'previous_time'
'previous_time',
'properties'
]
)

Expand Down
6 changes: 3 additions & 3 deletions tests/api/test_impressions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from splitio.storage.inmemmory import InMemoryTelemetryStorage, InMemoryTelemetryStorageAsync

impressions_mock = [
Impression('k1', 'f1', 'on', 'l1', 123456, 'b1', 321654),
Impression('k2', 'f2', 'off', 'l1', 123456, 'b1', 321654),
Impression('k3', 'f1', 'on', 'l1', 123456, 'b1', 321654)
Impression('k1', 'f1', 'on', 'l1', 123456, 'b1', 321654, {}),
Impression('k2', 'f2', 'off', 'l1', 123456, 'b1', 321654, {}),
Impression('k3', 'f1', 'on', 'l1', 123456, 'b1', 321654, {})
]
expectedImpressions = [{
'f': 'f1',
Expand Down
18 changes: 9 additions & 9 deletions tests/client/test_input_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,17 @@ def _configs(treatment):

def test_valid_properties(self, mocker):
"""Test valid_properties() method."""
assert input_validator.valid_properties(None) == (True, None, 1024)
assert input_validator.valid_properties([]) == (False, None, 0)
assert input_validator.valid_properties(True) == (False, None, 0)
assert input_validator.valid_properties(dict()) == (True, None, 1024)
assert input_validator.valid_properties({2: 123}) == (True, None, 1024)
assert input_validator.valid_properties(None, '') == (True, None, 1024)
assert input_validator.valid_properties([], '') == (False, None, 0)
assert input_validator.valid_properties(True, '') == (False, None, 0)
assert input_validator.valid_properties(dict(), '') == (True, None, 1024)
assert input_validator.valid_properties({2: 123}, '') == (True, None, 1024)

class Test:
pass
assert input_validator.valid_properties({
"test": Test()
}) == (True, {"test": None}, 1028)
}, '') == (True, {"test": None}, 1028)

props1 = {
"test1": "test",
Expand All @@ -519,7 +519,7 @@ class Test:
"test5": [],
2: "t",
}
r1, r2, r3 = input_validator.valid_properties(props1)
r1, r2, r3 = input_validator.valid_properties(props1, '')
assert r1 is True
assert len(r2.keys()) == 5
assert r2["test1"] == "test"
Expand All @@ -532,12 +532,12 @@ class Test:
props2 = dict()
for i in range(301):
props2[str(i)] = i
assert input_validator.valid_properties(props2) == (True, props2, 1817)
assert input_validator.valid_properties(props2, '') == (True, props2, 1817)

props3 = dict()
for i in range(100, 210):
props3["prop" + str(i)] = "a" * 300
r1, r2, r3 = input_validator.valid_properties(props3)
r1, r2, r3 = input_validator.valid_properties(props3, '')
assert r1 is False
assert r3 == 32952

Expand Down
Loading