Fixed a bug related to default values.

This commit is contained in:
Ege Emir Özkan
2020-08-14 12:01:01 +03:00
parent 2e14aeaace
commit b7e915d6db
3 changed files with 6 additions and 1 deletions

View File

@@ -132,6 +132,9 @@ def _migrate_records(class_: type, database_name: str, data,
new_records = _modify_records(data, col_to_del, col_to_add, flow) new_records = _modify_records(data, col_to_del, col_to_add, flow)
for record in new_records: for record in new_records:
del record['obj_id'] del record['obj_id']
keys_to_delete = [key for key in record if record[key] is None]
for key in keys_to_delete:
del record[key]
class_(**record).create_entry() class_(**record).create_entry()

View File

@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup( setuptools.setup(
name="datalite", # Replace with your own username name="datalite", # Replace with your own username
version="0.5.3", version="0.5.4",
author="Ege Ozkan", author="Ege Ozkan",
author_email="egeemirozkan24@gmail.com", author_email="egeemirozkan24@gmail.com",
description="A small package that binds dataclasses to an sqlite database", description="A small package that binds dataclasses to an sqlite database",

View File

@@ -40,6 +40,7 @@ class Migrate1:
@dataclass @dataclass
class Migrate2: class Migrate2:
cardinal: int cardinal: int
str_: str = "default"
def getValFromDB(obj_id = 1): def getValFromDB(obj_id = 1):
@@ -153,6 +154,7 @@ class DatabaseMigration(unittest.TestCase):
basic_migrate(Migrate1, {'ordinal': 'cardinal'}) basic_migrate(Migrate1, {'ordinal': 'cardinal'})
t_objs = fetch_all(Migrate1) t_objs = fetch_all(Migrate1)
self.assertEqual([obj.ordinal for obj in self.objs], [obj.cardinal for obj in t_objs]) self.assertEqual([obj.ordinal for obj in self.objs], [obj.cardinal for obj in t_objs])
self.assertEqual(["default" for _ in range(10)], [obj.str_ for obj in t_objs])
def tearDown(self) -> None: def tearDown(self) -> None:
t_objs = fetch_all(Migrate1) t_objs = fetch_all(Migrate1)