Skip to content

Conversation

@tconkling
Copy link
Contributor

This is a prelude commit to incoming FileUploader-related changes.

Motivation

Each ReportSession has a unique ID, but the server doesn't currently have a good way to retrieve a ReportSession by its ID. Instead, the Server currently maintains a dictionary that maps WebsocketHandlers -> ReportSessions.

This patch essentially just changes that dictionary to be a mapping of SessionID -> ReportSession, which will enable other HTTP endpoints to refer to running ReportSessions by ID. The upcoming FileUploader HTTP endpoint will use this to add an uploaded file to its associated ReportSession.

Details

  • ReportSession.id is now a str instead of an int. (This isn't strictly necessary, but it simplifies some things, and also allows us to easily make report session ID unguessable in the future - if this is a concern - by using a UUID.)
  • Server._session_infos is now Server._session_info_by_id, and stores a mapping of string ID to SessionInfo.
  • SessionInfo now holds its associated WebsocketHandler in addition to the ReportSession.
  • Tests are updated, and there's a bit more rigor in the logic for opening and closing new ReportSessions.

@tconkling tconkling requested a review from a team as a code owner February 5, 2020 17:16
@tconkling tconkling requested a review from monchier February 5, 2020 18:12
Copy link
Collaborator

@monchier monchier left a comment

Choose a reason for hiding this comment

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

I started a review, but wants to spend some more time. @tconkling I am assuming you are not going to land this today. Let me know if in a hurry.

Comment on lines +289 to +290
"""Create a mock ReportSession. Each mocked instance will have
its own unique ID."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point we said to use plain # for descriptions of private methods.

Comment on lines +301 to +303
"""Mock the Server's ReportSession import. We don't want
actual sessions to be instantiated, or scripts to be run.
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point we said to use plain # for descriptions of private methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoa, really? I strongly disagree with, and am confused by, that. For example, my IDE auto-parses docstrings to provide inline context.

What do we gain by having two different methods for documenting methods?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think """ """ are picked up by documentation tools.

I don't have a strong opinion and I won't block this PR for this. @tvst?

Copy link
Collaborator

@monchier monchier left a comment

Choose a reason for hiding this comment

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

Just minor notes.

Comment on lines +449 to +452
assert len(self._session_info_by_id) == 1
LOGGER.debug("Reusing preheated context for ws %s", ws)
session = self._session_info_by_id[PREHEATED_REPORT_SESSION].session
del self._session_info_by_id[PREHEATED_REPORT_SESSION]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if all this could be put in a function. It seems this is a get_preheaded_report_session.

Comment on lines +461 to +464
assert session.id not in self._session_info_by_id, (
"session.id '%s' registered multiple times!" % session.id
)
self._session_info_by_id[session.id] = SessionInfo(ws, session)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. Could this be get_session_info? So that we wrap the check in it/

Comment on lines +484 to +485
session_info = self._session_info_by_id[session_id]
del self._session_info_by_id[session_id]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another function? BTW, fine if you think this is just a couple of extra lines and it is more readable.

* develop: (30 commits)
  [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)
  Fix an incomplete copy for a dict that's then modified. (streamlit#1078)
  Fix indentation error in fad994c. (streamlit#1084)
  Widgets unit tests (streamlit#1077)
  [mypy] First phase of work on testing Python type annotations. (streamlit#1079)
  Add CircleCI jobs to run the oldest and newest Python versions we support. (streamlit#1053)
  Improve docs (streamlit#1075)
  Adding CORS to troubleshooting guide. (streamlit#1001)
  Fix for the CORS check (streamlit#965)
  Advanced caching updates feb (streamlit#1040)
  ...
@tconkling tconkling merged commit d14d241 into streamlit:develop Feb 19, 2020
@tconkling tconkling deleted the tim/StoreReportSessionsByID branch February 19, 2020 19:19
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