Skip to content

Commit 9ba04e6

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2623352 commit 9ba04e6

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

model_clone/utils.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from django.db.transaction import TransactionManagementError
77

88

9-
def create_copy_of_instance(instance, attrs=None, exclude=(), save_new=True, using=None):
9+
def create_copy_of_instance(
10+
instance, attrs=None, exclude=(), save_new=True, using=None
11+
):
1012
"""
1113
Clone an instance of `django.db.models.Model`.
1214
@@ -111,7 +113,9 @@ def unpack_unique_constraints(opts, only_fields=()):
111113
:return: Flat list of fields.
112114
"""
113115
fields = []
114-
constraints = getattr(opts, "total_unique_constraints", getattr(opts, "constraints", []))
116+
constraints = getattr(
117+
opts, "total_unique_constraints", getattr(opts, "constraints", [])
118+
)
115119
for constraint in constraints:
116120
fields.extend([f for f in constraint.fields if f in only_fields])
117121
return fields
@@ -240,7 +244,9 @@ def generate_value(value, suffix, transform, max_length, max_attempts):
240244
yield get_value(value, suffix, transform, max_length, i)
241245

242246
raise StopIteration(
243-
"CloneError: max unique attempts for {} exceeded ({})".format(value, max_attempts)
247+
"CloneError: max unique attempts for {} exceeded ({})".format(
248+
value, max_attempts
249+
)
244250
)
245251

246252

@@ -293,11 +299,19 @@ def get_fields_and_unique_fields_from_cls(
293299
if not getattr(f, "primary_key", False):
294300
if clone_fields and not force and not getattr(f, "one_to_one", False):
295301
valid = f.name in clone_fields
296-
elif clone_excluded_fields and not force and not getattr(f, "one_to_one", False):
302+
elif (
303+
clone_excluded_fields
304+
and not force
305+
and not getattr(f, "one_to_one", False)
306+
):
297307
valid = f.name not in clone_excluded_fields
298308
elif clone_o2o_fields and not force and getattr(f, "one_to_one", False):
299309
valid = f.name in clone_o2o_fields
300-
elif clone_excluded_o2o_fields and not force and getattr(f, "one_to_one", False):
310+
elif (
311+
clone_excluded_o2o_fields
312+
and not force
313+
and getattr(f, "one_to_one", False)
314+
):
301315
valid = f.name not in clone_excluded_o2o_fields # pragma: no cover
302316
else:
303317
valid = True
@@ -320,7 +334,9 @@ def get_fields_and_unique_fields_from_cls(
320334
for f in fields
321335
if not f.auto_created
322336
and (
323-
f.unique or f.name in unique_field_names or f.name in unique_constraint_field_names
337+
f.unique
338+
or f.name in unique_field_names
339+
or f.name in unique_constraint_field_names
324340
)
325341
]
326342

0 commit comments

Comments
 (0)