From 69ca09623a68c12f3644b57147c84debe75c7f46 Mon Sep 17 00:00:00 2001 From: Scott Griffin Date: Tue, 28 Apr 2015 04:53:10 +0000 Subject: [PATCH 1/2] Incremented version # --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7438f85..e65a403 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='django-bulk-update', - version='1.1.2', + version='1.1.2.2', packages=find_packages(), include_package_data=True, description='Bulk update using one query over Django ORM.', From 26f459eca1105a0730186e26b3d2eda1ddba6eeb Mon Sep 17 00:00:00 2001 From: Scott Griffin Date: Tue, 28 Apr 2015 17:32:51 +0000 Subject: [PATCH 2/2] Added check for 0 count objs. If there are no objects then there is nothing to update. Just return. --- bulk_update/helper.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bulk_update/helper.py b/bulk_update/helper.py index 4d383bd..4a7f163 100644 --- a/bulk_update/helper.py +++ b/bulk_update/helper.py @@ -36,11 +36,18 @@ def bulk_update(objs, meta=None, update_fields=None, exclude_fields=None, using='default', batch_size=None): assert batch_size is None or batch_size > 0 + obj_count = None # if we have a QuerySet, avoid loading objects into memory if isinstance(objs, QuerySet): - batch_size = batch_size or objs.count() + obj_count = objs.count() + batch_size = batch_size or obj_count else: - batch_size = batch_size or len(objs) + obj_count = len(objs) + batch_size = batch_size or obj_count + + # If there are not objects to update just exit. + if obj_count == 0: + return connection = connections[using] if meta is None: