Skip to content

Commit

Permalink
Merge pull request #787 from yuvipanda/json-no-mangle
Browse files Browse the repository at this point in the history
Don't sort keys by default in tojson when rendering profile forms
  • Loading branch information
minrk committed Sep 19, 2023
2 parents 574ca3f + 46d561d commit d60146f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,18 @@ def _render_options_form(self, profile_list):
)

env = Environment(loader=loader)

# jinja2's tojson sorts keys in dicts by default. This was useful
# in the time when python's dicts were not ordered. However, now that
# dicts are ordered in python, this screws it up. Since profiles are
# dicts, ordering *does* matter - they should be displayed to the user
# in the order that the admin sets them. This allows template writers
# to use `|tojson` on the profile_list (to be read by JS)
# without worrying about ordering getting mangled. Template writers
# can still sort keys by explicitly using `|dictsort` in their
# template
env.policies['json.dumps_kwargs'] = {'sort_keys': False}

if self.profile_form_template != "":
profile_form_template = env.from_string(self.profile_form_template)
else:
Expand Down

0 comments on commit d60146f

Please sign in to comment.