Skip to content

Preserve equal-key value order in sortedvalues - #701

Open
Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/stable-sorted-values
Open

Gambit-Checkmate wants to merge 1 commit into
mahmoud:masterfrom
Gambit-Checkmate:fix/stable-sorted-values

Conversation

@Gambit-Checkmate

@Gambit-Checkmate Gambit-Checkmate commented Nov 1, 2026 •

Copy link
Copy Markdown

The change

Fixes #700.

OrderedMultiDict.sortedvalues sorts each key's values in the requested direction and then consumes that sorted group forwards. This preserves the insertion order of equal-key values in both directions, matching Python's stable sort, while preserving every original key position. The former opposite-direction sort followed by pop() also reversed ties.

Mirror the fix in the embedded urlutils.OrderedMultiDict, covering QueryParamDict and parsed URL query parameters. Clarify that the key callback receives a value, and document tie stability. Add an unreleased changelog entry; no dependency or version change.

Validation on Windows / CPython 3.13.13:

  • Eight regression cases all fail on pristine master d31d821 and pass after the fix. They cover both sort directions, OrderedMultiDict, FastIterOrderedMultiDict, QueryParamDict and parsed URL queries; assert key positions, input preservation, value identity and one callback invocation per value.
  • Full unit/doctest suite: 782 passed, 1 skipped, 22 subtests passed.
  • Ruff E9/F for both changed modules and the new test: passed; new-test formatting: passed.
  • Python 3.7 syntax parsing, compileall, git diff --check, source distribution and wheel build: passed.

No coverage percentage is claimed. Other interpreters/platforms have not been run locally. Hosted Tests run 41269961822 requires upstream approval (action_required); no hosted tests have executed.

The backstory

Previous contribution context: #601, folded into #609. This defect was found by source inspection while checking the ordering guarantees of sortedvalues, not through production use. The issue contains a minimal reproduction; I checked the current open PR inventory and all-state sortedvalues/stable-sort searches before reporting it.

AI assistance

  • Harness/tooling: OpenAI Codex, GitHub CLI, Python/pytest and Ruff.

  • Model(s): GPT-6 family; exact deployment identifier unavailable.

  • Original prompt(s), relevant excerpts from the recurring user instruction, kept verbatim (the full instruction also includes private local workflow details):

    每天早上 8 点在本会话实际提交两个高质量的开源贡献 PR,把创建并获得 GitHub PR 链接作为每日完成目标。

    没有合适公开 issue 时可以检查代码、复现真实缺陷,确认无重复后报告问题并提交独立修复。

    只有改动真实、有依据、验证充分且账号有权限时才推送分支并创建 PR;绝不降低 star 门槛,不提交空改动、无关改动、未经验证或重复 PR,尊重上游 AI 贡献和认领规则。

The agent selected the specific defect, prepared the implementation and tests, and ran the checks above. No production usage or independent human code review is claimed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sortedvalues reverses the order of equal-key values

1 participant