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

use OrderDict because csv.DictReader returns a dict after version 3.7 #2496

Merged
merged 2 commits into from
Aug 15, 2021

Conversation

andreas-stuerz
Copy link
Contributor

@fraenki
Copy link
Member

fraenki commented Aug 10, 2021

LGTM, I'll apply the same fix for the statistics script.

@AdSchellevis
Copy link
Member

I don't want to spoil the fun here, but are we sure we're fixing the right thing? The end result seems to be a dict() anyway

@kulikov-a
Copy link
Member

@AdSchellevis imho not just a dict() is needed, but an OrderedDict for move_to_end() to work at

row['id'] = f"{row['pxname']}/{row['svname']}"
row.move_to_end('id', last=False)
servers.append(dict(row))

@AdSchellevis
Copy link
Member

@kulikov-a it won't stick to the end when casting to dict() later on :) (if it does, it's pure luck)

@kulikov-a
Copy link
Member

@AdSchellevis ah, got it, thanks. but shouldn't the order be preserved if (starting from 3.7) it is declared that the dict() preserves the insertion order (https://docs.python.org/3/whatsnew/3.7.html)?

@andreas-stuerz
Copy link
Contributor Author

@AdSchellevis
This fixes the bug and don´t modifiy the existing structure as casting to a dict should preserve the order. But maybe me, @kulikov-a and the python guys are overlooking something? Do you have any other information?

@AdSchellevis
Copy link
Member

@kulikov-a I kind of missed that item in the release notes, my point just is that if the order doesn't matter in real life, best don't try to make it look like it does..... trusting ordering in named array types is often quite dangerous and prone to errors. Eventually it wraps into a json container, which likely doesn't care about order either.

It's not my code, if @fraenki choses to accept it I don't mind, spending years on reverse engineering of all sorts of weirdness in our old code just makes my eyes hurt.

@kulikov-a
Copy link
Member

@AdSchellevis thanks for the explanation. thought that json.dump() just inherits the dict() behavior and now the order should be preserved for json too (https://docs.python.org/3.8/library/json.html).
@Andeman sorry for the discussion. just trying to learn something

@AdSchellevis
Copy link
Member

@kulikov-a that is good to know, but since it wasn't earlier, its likely safe to assume order doesn't matter (in which case someone could just add "id" to the container and be done with it)

@fraenki
Copy link
Member

fraenki commented Aug 15, 2021

I can confirm that it fixes the maintenance page, so the targeted issues is solved.

@fraenki fraenki merged commit 1001fa8 into opnsense:master Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants