Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotted key ordering isn't always preserved #163

Open
Tracked by #91
epage opened this issue Sep 3, 2021 · 8 comments · May be fixed by #165 or #808
Open
Tracked by #91

Dotted key ordering isn't always preserved #163

epage opened this issue Sep 3, 2021 · 8 comments · May be fixed by #165 or #808
Labels
A-output Area: Outputting TOML C-bug Category: Things not working as expected

Comments

@epage
Copy link
Member

epage commented Sep 3, 2021

hello.world = "a"
goodbye = "b"
hello.moon = "c"

gets turned into

hello.world = "a"
hello.moon = "c"
goodbye = "b"
@epage epage mentioned this issue Sep 3, 2021
6 tasks
epage added a commit to epage/toml_edit that referenced this issue Sep 3, 2021
@epage epage linked a pull request Sep 3, 2021 that will close this issue
@epage
Copy link
Member Author

epage commented Sep 3, 2021

If/when we add position information, a next step is to see if we can infer an inserted values position based on the parent dotted table. This would have us automatically organize new keys as is encouraged in the TOML spec

@epage epage added the C-bug Category: Things not working as expected label Sep 9, 2021
@epage epage added the A-output Area: Outputting TOML label Sep 23, 2022
@ofek
Copy link

ofek commented Nov 18, 2023

Has there been any progress on this?

@epage
Copy link
Member Author

epage commented Nov 18, 2023

Generally, if there were, they'd already be posted here or in a linked issue

Overall, the use of dotted keys seems small and alt ordering being even smaller as its non-idiomatic, that this hasn't been a priority for me. If someone else wants to pick up the work, they are welcome to.

@ofek
Copy link

ofek commented Nov 18, 2023

Thanks, I was just curious as I'm thinking about making Python bindings.

@fenollp
Copy link

fenollp commented Mar 11, 2024

Hi! Drive by question:
What/where is the struct or tree holding the collection of values dotted and otherwise and how can we make that type and its underlying values types "sort" in insertion order?

@epage
Copy link
Member Author

epage commented Mar 11, 2024

As this is isn't a focus area / priority of mine, it will be up to you to do some leg work on investigating this.

@crazymerlyn
Copy link

Looked into it and the cause seems to be the recursive way the the structure is stored. KeyValuePairs is an IndexMap so it should already maintain the order. But for dotted keys, hello.moon's top level key is just hello, the same as hello.world. As a result, when traversing, hello.world and hello.moon are bunched together before goodbye.

mxndtaylor added a commit to mxndtaylor/toml-rs-toml that referenced this issue Nov 9, 2024
mxndtaylor pushed a commit to mxndtaylor/toml-rs-toml that referenced this issue Nov 9, 2024
mxndtaylor added a commit to mxndtaylor/toml-rs-toml that referenced this issue Nov 9, 2024
mxndtaylor added a commit to mxndtaylor/toml-rs-toml that referenced this issue Nov 10, 2024
@mxndtaylor mxndtaylor linked a pull request Nov 10, 2024 that will close this issue
@mxndtaylor
Copy link

mxndtaylor commented Nov 10, 2024

I've just raised a PR to fix this - #808 I won't pretend its the most elegant solution, but it does seem to work.

Feedback welcome, I don't mind taking a new approach; I'm honestly not the most experienced with rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-output Area: Outputting TOML C-bug Category: Things not working as expected
Projects
None yet
5 participants