Skip to content
This repository has been archived by the owner. It is now read-only.

Handle no objs #3

Merged
merged 2 commits into from Apr 28, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Added check for 0 count objs.

If there are no objects then there is nothing to update. Just
return.
  • Loading branch information
Scott Griffin
Scott Griffin committed Apr 28, 2015
commit 26f459eca1105a0730186e26b3d2eda1ddba6eeb
@@ -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:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.