Skip to content

fix: keep the backend order in middlewares #314

Closed

Description

@uniqueg

Problem

The task distribution middlewares remove duplicate backends with
list(set(...)) (TaskDistributionBaseClass._set_tes_urls(), the random
and distance-based middlewares). That loses the order of
custom.tes.service_list and the discovered backends that
get_backends() returns; with Python's hash randomization the order even
differs between processes. So the base class (usable as a middleware of
its own) forwards in an arbitrary order instead of the configured one,
and the distance-based middleware orders backends at the same distance
arbitrarily. The tests worked around it (fixture in_order).

Proposal

De-duplicate with dict.fromkeys() (first occurrence wins, order kept)
everywhere in the task distribution middlewares; document the order.

Acceptance criteria

  • The base class keeps the configured order (first occurrences);
    backends at the same distance keep their order (both
    permutations); the random order depends on the random state only
    (tests fail with the old code under several PYTHONHASHSEEDs).
  • Docs (docs/middlewares.md) state the order.
  • ruff, mypy, ast-grep, semgrep, pytest (100% coverage),
    mkdocs build --strict pass locally.

Verification (local)

As #313: all checks pass (1039 passed, 80 skipped; 100%
coverage). Not run: smoke test, MongoDB 7.0 matrix entry.

Dependencies

Open questions

  • None.

Activity

  1. added
    priority: medium
    status: in progress
    type: bug
    workload: hours
    on Oct 24, 2026
  2. removed
    status: in progress
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: bugworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions