Skip to content

Commit a3c67b8

Browse files
fix: dedupe command FieldError with only("id") and select_related (#14350)
Using findings.only("id") while select_related traversal was still active on the queryset caused a FieldError. Clear both select_related and prefetch_related before calling only("id") so the async dispatch path works regardless of how the queryset was constructed. Also switch --dedupe_batch_mode from store_true to BooleanOptionalAction so the flag can be explicitly disabled with --no-dedupe_batch_mode. Co-authored-by: Ross E Esposito <ross@defectdojo.com>
1 parent 9147099 commit a3c67b8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

dojo/management/commands/dedupe.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
import logging
23

34
import pghistory
@@ -53,7 +54,7 @@ def add_arguments(self, parser):
5354
parser.add_argument("--dedupe_sync", action="store_true", help="Run dedupe in the foreground, default false")
5455
parser.add_argument(
5556
"--dedupe_batch_mode",
56-
action="store_true",
57+
action=argparse.BooleanOptionalAction,
5758
default=True,
5859
help="Deduplicate in batches (similar to import), works with both sync and async modes (default: True)",
5960
)
@@ -130,12 +131,13 @@ def _run_dedupe(self, *, restrict_to_parsers, hash_code_only, dedupe_only, dedup
130131
elif dedupe_sync:
131132
mass_model_updater(Finding, findings, do_dedupe_finding_task_internal, fields=None, order="desc", page_size=100, log_prefix="deduplicating ")
132133
else:
133-
# async tasks only need the id
134+
# async tasks only need the id; clear select/prefetch_related to avoid
135+
# FieldError when combining only("id") with select_related traversal
134136
from dojo.celery_dispatch import dojo_dispatch_task # noqa: PLC0415 circular import
135137

136138
mass_model_updater(
137139
Finding,
138-
findings.only("id"),
140+
findings.select_related(None).prefetch_related(None).only("id"),
139141
lambda f: dojo_dispatch_task(do_dedupe_finding_task, f.id),
140142
fields=None,
141143
order="desc",

0 commit comments

Comments
 (0)