@@ -564,7 +564,7 @@ def validate_factory_instantiation(sdk_key):
564
564
return True
565
565
566
566
567
- def valid_properties (properties ):
567
+ def valid_properties (properties , source ):
568
568
"""
569
569
Check if properties is a valid dict and returns the properties
570
570
that will be sent to the track method, avoiding unexpected types.
@@ -580,7 +580,7 @@ def valid_properties(properties):
580
580
return True , None , size
581
581
582
582
if not isinstance (properties , dict ):
583
- _LOGGER .error ('track : properties must be of type dictionary.' )
583
+ _LOGGER .error ('%s : properties must be of type dictionary.' , source )
584
584
return False , None , 0
585
585
586
586
valid_properties = dict ()
@@ -595,9 +595,8 @@ def valid_properties(properties):
595
595
if element is None :
596
596
continue
597
597
598
- if not isinstance (element , str ) and not isinstance (element , Number ) \
599
- and not isinstance (element , bool ):
600
- _LOGGER .warning ('Property %s is of invalid type. Setting value to None' , element )
598
+ if not _check_element_type (element ):
599
+ _LOGGER .warning ('%s: Property %s is of invalid type. Setting value to None' , source , element )
601
600
element = None
602
601
603
602
valid_properties [property ] = element
@@ -607,16 +606,22 @@ def valid_properties(properties):
607
606
608
607
if size > MAX_PROPERTIES_LENGTH_BYTES :
609
608
_LOGGER .error (
610
- 'The maximum size allowed for the properties is 32768 bytes. ' +
611
- 'Current one is ' + str (size ) + ' bytes. Event not queued'
612
- )
609
+ '%s: The maximum size allowed for the properties is 32768 bytes. ' +
610
+ 'Current one is ' + str (size ) + ' bytes. Event not queued' , source )
613
611
return False , None , size
614
612
615
613
if len (valid_properties .keys ()) > 300 :
616
- _LOGGER .warning ('Event has more than 300 properties. Some of them will be trimmed' +
617
- ' when processed' )
614
+ _LOGGER .warning ('%s: Event has more than 300 properties. Some of them will be trimmed' +
615
+ ' when processed' , source )
618
616
return True , valid_properties if len (valid_properties ) else None , size
619
617
618
+ def _check_element_type (element ):
619
+ if not isinstance (element , str ) and not isinstance (element , Number ) \
620
+ and not isinstance (element , bool ):
621
+ return False
622
+
623
+ return True
624
+
620
625
def validate_pluggable_adapter (config ):
621
626
"""
622
627
Check if pluggable adapter contains the expected method signature
0 commit comments