Skip to content

Conversation

@nthmost
Copy link
Contributor

@nthmost nthmost commented Feb 18, 2020

Issue: #975

Description: Currently, st.json will trip over the use of a nonstandard key in a dictionary, resulting in a confusing and unhelpful traceback to the user.

This PR wraps the conversion to JSON in a try-except block that catches the TypeError that arises from use of weird keys that json.dumps cannot handle. If triggered, we show a warning to the user that this happened, and then rerun json.dumps with skipkeys=True.

The resultant data structure will not show the entire data, but the warning should be informative enough to the user to understand why.


Contribution License Agreement

By submiting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@nthmost nthmost requested a review from a team as a code owner February 18, 2020 21:49
Copy link
Contributor

@arraydude arraydude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@arraydude
Copy link
Contributor

Should we add a test for this behavior?

@nthmost
Copy link
Contributor Author

nthmost commented Feb 18, 2020

Should we add a test for this behavior?

Sure, I'll do that.

@nthmost nthmost merged commit c8f8a19 into streamlit:develop Feb 19, 2020
@nthmost nthmost deleted the protect_st_json_against_weird_keys_975 branch February 19, 2020 20:00
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 19, 2020
# By Nahuel Emiliano Rosso Fandiño (1) and others
# Via GitHub
* develop:
  Show warning to user and use skipkeys=True if json.dumps causes TypeError (streamlit#1112)
  Server: store SessionInfo by id (streamlit#1056)
  [Screencast] Fixing countdown bug (streamlit#1082)

# Conflicts:
#	lib/streamlit/server/Server.py
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 24, 2020
* develop: (53 commits)
  Update plotly.js to 1.52 (streamlit#1119)
  Add tooltip in Altair/Vega-lite docstring code (streamlit#1092)
  Ability to bind to a server address with server.address config option (streamlit#1107)
  [mypy] Enable check_untyped_defs throughout the codebase. (streamlit#1110)
  st.map: set "radiusMinPixels" to 3 (streamlit#1113)
  st.plotly_chart docs incorrectly refer to Altair (streamlit#1118)
  Fix BytesIO and numpy array data sources for audio/video (streamlit#1116)
  Show warning to user and use skipkeys=True if json.dumps causes TypeError (streamlit#1112)
  Server: store SessionInfo by id (streamlit#1056)
  [Screencast] Fixing countdown bug (streamlit#1082)
  Release 0.56.0 (streamlit#1101)
  Fix bug where icon assets were missing from "make install" (streamlit#1100)
  Clean signatures of wrapped DeltaGenerator methods (streamlit#1099)
  Using widgetId as the key when rendering elements (streamlit#1102)
  Pass --skip-lock to pipenv under pipenv-install Makefile target. (streamlit#1093)
  Allow wider range of int-like types in NumberInput (streamlit#1087)
  Fix missing caching URL (streamlit#1094)
  Version 0.55.1 (just pointing to new docs) (streamlit#1089)
  Retire python-3.7.4 CircleCI project. (streamlit#1086)
  Handle different Caching error messages (streamlit#1068)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants