From ef961207f798b6fb90cd8514d2a38001b8926e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jay=20=E8=A9=B9?= Date: Fri, 24 Sep 2021 01:55:35 +0800 Subject: [PATCH 1/2] fix_do_not_create_if_bulk_list_None --- sqlbatis/sqlbatis_dao.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sqlbatis/sqlbatis_dao.py b/sqlbatis/sqlbatis_dao.py index 3938168..27677cf 100644 --- a/sqlbatis/sqlbatis_dao.py +++ b/sqlbatis/sqlbatis_dao.py @@ -115,9 +115,12 @@ def bulk_insert(self, attrs): :return: TBI :rtype: TBI """ - with self.SQLBatis.get_connection() as conn: - result = conn.execute(self.table.insert().values(attrs)) - return result + if len(attrs) > 0: + with self.SQLBatis.get_connection() as conn: + result = conn.execute(self.table.insert().values(attrs)) + return result + + return None def _get_table_name(self): """ From 0146521236a1bc1769ff11080d4d5ebab1c6ed08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jay=20=E8=A9=B9?= Date: Wed, 13 Oct 2021 18:25:29 +0800 Subject: [PATCH 2/2] add_insert_null_list_test --- tests/crud.py | 2 ++ tests/test_basic_dao.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/tests/crud.py b/tests/crud.py index b8f9f5c..b72b54f 100644 --- a/tests/crud.py +++ b/tests/crud.py @@ -53,4 +53,6 @@ def bulk_create(users): 'name': 'leo3' }] +users_null = [] + users_for_paged = [user for i in range(35)] diff --git a/tests/test_basic_dao.py b/tests/test_basic_dao.py index 46df5dd..c829d88 100644 --- a/tests/test_basic_dao.py +++ b/tests/test_basic_dao.py @@ -50,6 +50,14 @@ def test_5_bulk_insert(self): results = user_dao.retrieve_all().all() assert len(results) == 4 + def test_6_bulk_insert_null(self): + user_dao = UserDao() + pre_res = user_dao.retrieve_all().all() + user_dao.bulk_insert(users_null) + results = user_dao.retrieve_all().all() + + assert len(results) == len(pre_res) + if __name__ == '__main__': unittest.main()