Handle null values in state

This commit is contained in:
simon987 2021-01-10 20:56:46 -05:00
parent b845d96295
commit b2efaa99a4
3 changed files with 17 additions and 1 deletions

View File

@ -160,6 +160,8 @@ def _sqlite_type(value):
def _serialize(value):
if isinstance(value, bytes):
return base64.b64encode(value)
if value is None:
return None
return str(value)

View File

@ -2,7 +2,7 @@ from setuptools import setup
setup(
name="hexlib",
version="1.20",
version="1.21",
description="Misc utility methods",
author="simon987",
author_email="me@simon987.net",

View File

@ -47,3 +47,17 @@ class TestPersistentState(TestCase):
val["id"] = 1
self.assertDictEqual(val, s["a"][1])
def test_none(self):
s = PersistentState()
val = {"a": 1, "b": None}
s["a"][1] = val
s["a"][1] = {
"a": None
}
val["a"] = None
val["id"] = 1
self.assertDictEqual(val, s["a"][1])