Skip to content

Commit d907949

Browse files
committed
code formatting
1 parent 9ae72e4 commit d907949

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

bulk_sync/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import OrderedDict
22
import logging
3+
34
from django.db import transaction
45
from django.core.exceptions import FieldDoesNotExist
56

@@ -16,7 +17,8 @@ def bulk_sync(
1617
`new_models`: Django ORM objects that are the desired state. They may or may not have `id` set.
1718
`key_fields`: Identifying attribute name(s) to match up `new_models` items with database rows. If a foreign key
1819
is being used as a key field, be sure to pass the `fieldname_id` rather than the `fieldname`.
19-
`filters`: Q() filters specifying the subset of the database to work in. Use `None` or `[]` if you want to sync against the entire table.
20+
`filters`: Q() filters specifying the subset of the database to work in. Use `None` or `[]` if you want to sync
21+
against the entire table.
2022
`batch_size`: passes through to Django `bulk_create.batch_size` and `bulk_update.batch_size`, and controls
2123
how many objects are created/updated per SQL query.
2224
`fields`: (optional) list of fields to update. If not set, will sync all fields that are editable and not
@@ -71,7 +73,7 @@ def get_key(obj):
7173

7274
if not skip_creates:
7375
db_class.objects.bulk_create(new_objs, batch_size=batch_size)
74-
76+
7577
if not skip_updates:
7678
db_class.objects.bulk_update(existing_objs, fields=fields, batch_size=batch_size)
7779

@@ -82,8 +84,8 @@ def get_key(obj):
8284
assert len(existing_objs) == len(new_models) - len(new_objs)
8385

8486
stats = {
85-
"created": 0 if skip_creates else len(new_objs),
86-
"updated": 0 if skip_updates else (len(new_models) - len(new_objs)),
87+
"created": 0 if skip_creates else len(new_objs),
88+
"updated": 0 if skip_updates else (len(new_models) - len(new_objs)),
8789
"deleted": 0 if skip_deletes else len(obj_dict)
8890
}
8991

runtest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515
test_runner = TestRunner()
1616
failures = test_runner.run_tests(["tests"])
1717
sys.exit(bool(failures))
18-

tests/tests.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ def test_provided_pk_is_retained_but_raises_if_mismatch_with_keyfield(self):
8484
ret = bulk_sync(new_models=new_objs, filters=Q(company_id=c1.id), key_fields=("name",))
8585

8686
self.assertEqual(0, ret["stats"]["updated"])
87-
self.assertEqual(1, ret["stats"]["created"]) # Added 'Notscott'
88-
self.assertEqual(1, ret["stats"]["deleted"]) # Deleted 'Scott'
87+
self.assertEqual(1, ret["stats"]["created"]) # Added 'Notscott'
88+
self.assertEqual(1, ret["stats"]["deleted"]) # Deleted 'Scott'
8989

9090
# Make sure we retained the PK
9191
self.assertEqual(Employee.objects.filter(id=unique_pk).count(), 1)
9292

93-
9493
def test_fields_parameter(self):
9594
c1 = Company.objects.create(name="Foo Products, Ltd.")
9695
c2 = Company.objects.create(name="Bar Microcontrollers, Inc.")
@@ -220,13 +219,11 @@ def test_skip_updates(self):
220219
self.assertEqual(2, Employee.objects.count())
221220
self.assertEqual(["Scott", "Alice"], [x.name for x in Employee.objects.all().order_by('id')])
222221

223-
224222
self.assertEqual(0, ret["stats"]["updated"])
225223
self.assertEqual(1, ret["stats"]["created"])
226224
self.assertEqual(1, ret["stats"]["deleted"])
227225

228226

229-
230227
class BulkCompareTests(TestCase):
231228
""" Test `bulk_compare` method """
232229

0 commit comments

Comments
 (0)