Repository navigation
implement json.enable and json.dump_func configs - #1541
Merged
Merged
Conversation
alisonatwork
force-pushed
the
fix-json-config
branch
from
September 15, 2026 05:49
2c21242 to
1d5b40b
Compare
Member
|
Looks good to me already. Tests, backwards compatibility, docs, all covered. Very nice! Since you force-pushed just 10 minutes ago I'll still wait a bit :) |
Contributor
Author
|
Yeah, sorry about that force-push, I realized the commit was connected to my work email address vs my personal one. Not a big deal, since we use Bottle at work, but just for consistency I like to try keep the same email everywhere. If you are happy with the MR, feel free to merge 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As discussed on #1539, the
json.enableconfig - which in 0.13 deprecated and replaced theautojsonapplication constructor arg - does nothing. This pull request updatesjson.enableso that it behaves asautojsonused to: an on/off switch for dict-to-JSON-by-default behavior. When it is off, dictionaries will be treated as iterable, resulting in the same output as a list or tuple of the keys.I've also implemented the
json.dump_funcconfig option, which can be used to replace the default (CPython or UltraJSON)dumps.There is a bit business logic complexity with the custom serialization function, because
JSONPluginstill allows passing ajson_dumpsfunction in its constructor. In practice the only way to usefully do that in 0.13 was to uninstall the defaultJSONPluginand reinstall a new one or else reach around and overwrite thejson_dumpsproperty on the installed plugin then callresetto reapply it (similar to solution described in #287 (comment)).I think the best way to support backward-compatibility here is to ignore both the
json.enableandjson.dump_funcconfigs if and only if theJSONPluginhad a customjson_dumpsset on it (whether through constructor or property set). The downside of this is that if you install a customJSONPluginthen you can't use config to enable or disable it per-route, but I am going to guess that this is not really a use case most people will ever have in real life.I am not sure how deep to go with updating the docs to describe this behavior, so open the PR first to see. Maybe it doesn't need to be documented because the configs are basically enough and should be the standard way going forward?