Skip to content

Commit 2abff7b

Browse files
committed
refactor(spp_import_match): deduplicate dryrun and sync import paths in execute_import
Merge the nearly identical dryrun and synchronous (<= 100 rows) blocks into a single conditional, reducing code duplication while preserving identical behavior.
1 parent eaeb6cd commit 2abff7b

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

spp_import_match/models/base_import.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,11 @@ def execute_import(self, fields, columns, options, dryrun=False):
6767
overwrite_match = options.get("overwrite_match", False)
6868
_import_match_local.counts = None
6969

70-
if dryrun:
71-
_logger.info("Doing dry-run import")
70+
if dryrun or len(input_file_data) <= 100:
71+
_logger.info("Doing %s import", "dry-run" if dryrun else "normal")
7272
if import_match_ids:
7373
self = self.with_context(import_match_ids=import_match_ids, overwrite_match=overwrite_match)
74-
result = super().execute_import(fields, columns, options, dryrun=True)
75-
counts = getattr(_import_match_local, "counts", None)
76-
if counts:
77-
result["import_match_counts"] = counts
78-
_import_match_local.counts = None
79-
return result
80-
81-
if len(input_file_data) <= 100:
82-
_logger.info("Doing normal import")
83-
if import_match_ids:
84-
self = self.with_context(import_match_ids=import_match_ids, overwrite_match=overwrite_match)
85-
result = super().execute_import(fields, columns, options, dryrun=False)
74+
result = super().execute_import(fields, columns, options, dryrun=dryrun)
8675
counts = getattr(_import_match_local, "counts", None)
8776
if counts:
8877
result["import_match_counts"] = counts

0 commit comments

Comments
 (0)