Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def db_value(self, val):
if type(val) in [int, float, Increment] or val is None:
return val
raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {int} or {float}, '
f'got {type(val)}')
def db_value(self, val):
if type(val) is dict or val is None:
# check if user defined to set the value as lower case
if self.model_cls._meta.to_lowercase:
return {k: v.lower() if type(v) is str else v for k,v in val.items()}
return val
raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {dict}, '
f'got {type(val)}')
def db_value(self, val):
if type(val) is bool or val is None:
return val
raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {bool}, '
f'got {type(val)}')
def db_value(self, val):
if any([
isinstance(val, DatetimeWithNanoseconds),
isinstance(val, datetime),
isinstance(val, Sentinel),
isinstance(val, type(None)),
]):
return val
raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {datetime}, '
f'got {type(val)}')
def attr_float_only(self, attr_val, field_val):
"""Method for attribute float_only"""
if attr_val and type(field_val) is not float:
raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {float} type, '
f'got {type(field_val)}')
return field_val
def db_value(self, val):
if type(val) in [list, ArrayUnion, ArrayRemove] or val is None:
# check if user defined to set the value as lower case
if self.model_cls._meta.to_lowercase:
return [v.lower() if type(v) is str else v for v in val]
return val
raise errors.InvalidFieldType(f'Invalid field type. Field "{self.name}" expected {list}, '
f'got {type(val)}')