fix(worker): prevent target duplication when running in worker mode (#1085)
Some checks are pending
release-please / release-please (push) Waiting to run
Tests / lint (3.11) (push) Waiting to run
Tests / unit (3.11) (push) Waiting to run
Tests / unit (3.8) (push) Waiting to run
Tests / integration (ubuntu-latest, 3.11) (push) Waiting to run
Tests / template (ubuntu-latest, 3.11) (push) Waiting to run
Tests / coverage (3.11) (push) Blocked by required conditions

Fixes #1069

When a task is dispatched via Celery (start_runner), both the Task
runner and the command runner create Target objects for the same inputs.
Since they share the same unique_name, self_targets counts both,
reporting "Loaded 2 targets" instead of 1.

Fixed by checking for existing Target names in prior results before
creating new Target objects from inputs.

Generated with [Claude Code](https://claude.ai/code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Fixed an issue where duplicate target result entries were being
created unnecessarily during runner initialization. The system now
checks for existing target entries before instantiating new ones,
eliminating redundant data and ensuring cleaner result sets.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/freelabz/secator/pull/1085)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Olivier Cervello <ocervell@users.noreply.github.com>
This commit is contained in:
Olivier Cervello 2026-05-12 14:37:42 +02:00 committed by GitHub
parent 3a87b099cc
commit b30e21355a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -198,9 +198,10 @@ class Runner:
self.debug(f'resolving inputs with {len(self.dynamic_opts)} dynamic opts', obj=self.dynamic_opts, sub='init')
self.inputs = [inputs] if not isinstance(inputs, list) else inputs
self.inputs = list(set(self.inputs))
targets = [Target(name=target) for target in self.inputs]
for target in targets:
self.add_result(target, print=False, output=False)
if self.caller != 'Task':
targets = [Target(name=target) for target in self.inputs]
for target in targets:
self.add_result(target, print=False, output=False)
# Run extractors on results
self._run_extractors()