Commit a2f85ff7 authored by Matias Guijarro's avatar Matias Guijarro

config/settings.py: convert to string when writing values to redis

Change in redis-py only allows bytes, strings or number values
parent d897a882
...@@ -38,16 +38,16 @@ def boolify(s, **keys): ...@@ -38,16 +38,16 @@ def boolify(s, **keys):
raise ValueError("Not Boolean Value!") raise ValueError("Not Boolean Value!")
def auto_conversion(var): def auto_coerce_from_redis(s):
"""guesses the str representation of the variables type""" """Convert variable to a new type from the str representation"""
if var is None: if s is None:
return None return None
for caster in (boolify, int, float): for caster in (boolify, int, float):
try: try:
return caster(var) return caster(s)
except (ValueError, TypeError): except (ValueError, TypeError):
pass pass
return var return s
def pickle_loads(var): def pickle_loads(var):
...@@ -161,8 +161,8 @@ class SimpleSetting(object): ...@@ -161,8 +161,8 @@ class SimpleSetting(object):
self, self,
name, name,
connection=None, connection=None,
read_type_conversion=auto_conversion, read_type_conversion=auto_coerce_from_redis,
write_type_conversion=None, write_type_conversion=str,
default_value=None, default_value=None,
): ):
if connection is None: if connection is None:
...@@ -250,8 +250,8 @@ class SimpleSettingProp(object): ...@@ -250,8 +250,8 @@ class SimpleSettingProp(object):
self, self,
name, name,
connection=None, connection=None,
read_type_conversion=auto_conversion, read_type_conversion=auto_coerce_from_redis,
write_type_conversion=None, write_type_conversion=str,
default_value=None, default_value=None,
use_object_name=True, use_object_name=True,
): ):
...@@ -301,8 +301,8 @@ class QueueSetting(object): ...@@ -301,8 +301,8 @@ class QueueSetting(object):
self, self,
name, name,
connection=None, connection=None,
read_type_conversion=auto_conversion, read_type_conversion=auto_coerce_from_redis,
write_type_conversion=None, write_type_conversion=str,
): ):
if connection is None: if connection is None:
connection = get_cache() connection = get_cache()
...@@ -448,8 +448,8 @@ class QueueSettingProp(object): ...@@ -448,8 +448,8 @@ class QueueSettingProp(object):
self, self,
name, name,
connection=None, connection=None,
read_type_conversion=auto_conversion, read_type_conversion=auto_coerce_from_redis,
write_type_conversion=None, write_type_conversion=str,
use_object_name=True, use_object_name=True,
): ):
self._name = name self._name = name
...@@ -492,8 +492,8 @@ class HashSetting(object): ...@@ -492,8 +492,8 @@ class HashSetting(object):
self, self,
name, name,
connection=None, connection=None,
read_type_conversion=auto_conversion, read_type_conversion=auto_coerce_from_redis,
write_type_conversion=None, write_type_conversion=str,
default_values={}, default_values={},
): ):
if connection is None: if connection is None:
...@@ -662,8 +662,8 @@ class HashSettingProp(object): ...@@ -662,8 +662,8 @@ class HashSettingProp(object):
self, self,
name, name,
connection=None, connection=None,
read_type_conversion=auto_conversion, read_type_conversion=auto_coerce_from_redis,
write_type_conversion=None, write_type_conversion=str,
default_values={}, default_values={},
use_object_name=True, use_object_name=True,
): ):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment