Skip to content

fix: preserve default-config key order in Configuration.dump - #200

Open
Sanjays2402 wants to merge 2 commits into
beetbox:mainfrom
Sanjays2402:fix/dump-default-key-order
Open

Sanjays2402 wants to merge 2 commits into
beetbox:mainfrom
Sanjays2402:fix/dump-default-key-order

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #195

Configuration.dump documents that key order comes from the default configuration, but it builds its mapping from flatten(), which walks keys() in source-priority order. A key present only in the defaults is therefore emitted after every key of the higher-priority user source — so in the reported case paths (a default key) landed after plugins and appeared to be under the Plugins header.

The dumped mapping now lists default-source keys first in their declared order, with any remaining keys appended. New test_dump_follows_default_key_order fails without the change and passes with it; the rest of the suite is unchanged (294 passed).

Configuration.dump documents that key order comes from the default
configuration, but it builds its mapping from flatten(), which walks
keys() in source-priority order. Any key present only in the defaults
was therefore emitted after every key of the higher-priority user
source, so a default key such as beets' paths could land inside a
later section (reported as appearing under the Plugins header).

Reorder the flattened mapping so keys declared by default sources come
first, in their declared order, with remaining keys appended.

Adds a regression test covering a user source that reorders keys.
@github-actions

Copy link
Copy Markdown

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@Sanjays2402

Copy link
Copy Markdown
Author

Done — added a changelog entry under Unreleased for the fix (Configuration.dump now preserves default-config key order).

@Imkkey Imkkey left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the interaction with full=False and redaction: default keys determine the output order without reintroducing omitted default-only values, and redacted values remain redacted. Multiple default sources with overlapping keys, empty or absent defaults, extra keys, nested mapping/list values and YAML comment sections also behaved correctly in the cases tested.

On 112aefb, the existing suite passed all 297 tests, and 21 additional focused checks passed. These were local checks on Python 3.12 against the PR's pinned base, not verification of GitHub Actions or integration with current main.

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.

beet config groups non-plugin config in the Plugins header if they appear after plugins

2 participants