Fix JSON loading on Python 3: keep strings as str in convertJsonUnicode#1245
Open
xairaven wants to merge 1 commit into
Open
Fix JSON loading on Python 3: keep strings as str in convertJsonUnicode#1245xairaven wants to merge 1 commit into
str in convertJsonUnicode#1245xairaven wants to merge 1 commit into
Conversation
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.
Summary
Fixes a bug in
convertJsonUnicodethat encoded JSON strings tobyteson Python 3. That conversion causedjson.dumps()to fail when saving topologies (TypeError: bytes not JSON serializable), which in turn produced empty.mnfiles and runtime errors such asKeyError: 'hosts'during load/save cycles.Root cause
The previous implementation converted all unicode strings to byte strings unconditionally. On Python 3,
stris the native text type and should not be encoded tobytes. Encoding resulted in non-serializable values inside the topology dictionary, breakingsaveTopology.Changes
convertJsonUnicodeto:strvalues unchanged on Python 3.Impact
TypeErrorfromjson.dumps()and the downstreamKeyError: 'hosts'observed duringloadTopology.sys.version_info[0] == 2).How to test
Start MiniEdit and open an existing
.mntopology (example JSON attached in issue).Verify the loaded values are
stron Python 3:Save the topology and confirm the .mn file is non-empty and contains expected keys (hosts, switches, controllers, links).
Basic smoke test: create topology in GUI, save, reopen, and check that nodes/links persist.
Notes
A temporary fallback in saveTopology (e.g. json.dumps(..., default=str)) is not included here because it masks the root cause. This PR fixes the root cause so that serialization proceeds normally.
If desired, we can add a small unit test for convertJsonUnicode to assert that strings remain str on Python 3.