diff --git a/.circleci/config.yml b/.circleci/config.yml index a817962452..176d3817c6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -385,7 +385,7 @@ jobs: PERCY_ENABLE: 1 PERCY_PARALLEL_TOTAL: -1 - parallelism: 4 + parallelism: 5 steps: - checkout: diff --git a/CHANGELOG.md b/CHANGELOG.md index b689c025ca..7b67f54c9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [2.3.1] - 2022-03-29 + +### Fixed + +- [#1963](https://github.com/plotly/dash/pull/1963) Fix [#1780](https://github.com/plotly/dash/issues/1780) flask shutdown deprecation warning when running dashduo threaded tests. +- [#1995](https://github.com/plotly/dash/pull/1995) Fix [#1992](https://github.com/plotly/dash/issues/1992) ImportError: cannot import name 'get_current_traceback' from 'werkzeug.debug.tbtools'. + ## [2.3.0] - 2022-03-13 ### Added diff --git a/README.md b/README.md index c56949f01d..1d33e645d4 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Built on top of [Plotly.js](https://github.com/plotly/plotly.js), [React](https: |![Sample Dash App](https://user-images.githubusercontent.com/1280389/30086128-9bb4a28e-9267-11e7-8fe4-bbac7d53f2b0.gif) | Here’s a simple example of a Dash App that ties a Dropdown to a Plotly Graph. As the user selects a value in the Dropdown, the application code dynamically exports data from Google Finance into a Pandas DataFrame. This app was written in just **43** lines of code ([view the source](https://gist.github.com/chriddyp/3d2454905d8f01886d651f207e2419f0)). | |![Crossfiltering Dash App](https://user-images.githubusercontent.com/1280389/30086123-97c58bde-9267-11e7-98a0-7f626de5199a.gif)|Dash app code is declarative and reactive, which makes it easy to build complex apps that contain many interactive elements. Here’s an example with 5 inputs, 3 outputs, and cross filtering. This app was composed in just 160 lines of code, all of which were Python.| |![Dash App with Mapbox map showing walmart store openings](https://user-images.githubusercontent.com/1280389/30086299-768509d0-9268-11e7-8e6b-626ac9ca512c.gif)| Dash uses [Plotly.js](https://github.com/plotly/plotly.js) for charting. About 50 chart types are supported, including maps. | -|![Financial report](https://github.com/plotly/dash-docs/blob/516f80c417051406210b94ea23a6d3b6cd84d146/assets/images/gallery/dash-financial-report.gif)| Dash isn't just for dashboards. You have full control over the look and feel of your applications. Here's a Dash App that's styled to look like a PDF report. | +|![Financial report](https://user-images.githubusercontent.com/2678795/161153710-57952401-6e07-42d5-ba3e-bab6419998c7.gif)| Dash isn't just for dashboards. You have full control over the look and feel of your applications. Here's a Dash App that's styled to look like a PDF report. | To learn more about Dash, read the [extensive announcement letter](https://medium.com/@plotlygraphs/introducing-dash-5ecf7191b503) or [jump in with the user guide](https://plotly.com/dash). @@ -53,4 +53,4 @@ Enterprise AI Features: Everything that your data science team needs to rapidly See [https://plotly.com/contact-us/](https://plotly.com/contact-us/) to get in touch. -![image](https://images.prismic.io/plotly-marketing-website/493eec39-8467-4610-b9d0-d6ad3ea61423_Dash+Open+source%2BDash+enterprise2-01.jpg?auto=compress,format) +![Dash Enterprise](https://user-images.githubusercontent.com/2678795/161155614-21c54a22-f821-4dda-b910-ee27e27fb5f2.png) diff --git a/components/dash-table/tests/selenium/test_sizing.py b/components/dash-table/tests/selenium/test_sizing.py index 707678aa41..d2f743e7e4 100644 --- a/components/dash-table/tests/selenium/test_sizing.py +++ b/components/dash-table/tests/selenium/test_sizing.py @@ -1,12 +1,7 @@ import dash -import pytest from utils import ( - basic_modes, get_props, - generate_mock_data, - generate_markdown_mock_data, - generate_mixed_markdown_data, ) from dash.dependencies import Input, Output @@ -294,12 +289,7 @@ def test_szng002_percentages_result_in_same_widths(test): assert test.get_log_errors() == [] -@pytest.mark.parametrize("props", basic_modes) -@pytest.mark.parametrize( - "data_fn", - [generate_mock_data, generate_markdown_mock_data, generate_mixed_markdown_data], -) -def test_szng004_on_focus(test, props, data_fn): +def on_focus(test, props, data_fn): app = dash.Dash(__name__) baseProps1 = get_props(data_fn=data_fn) diff --git a/components/dash-table/tests/selenium/test_sizing_x.py b/components/dash-table/tests/selenium/test_sizing_x.py new file mode 100644 index 0000000000..51dfefc046 --- /dev/null +++ b/components/dash-table/tests/selenium/test_sizing_x.py @@ -0,0 +1,13 @@ +import pytest + +from test_sizing import on_focus + +from utils import ( + basic_modes, + generate_mock_data, +) + + +@pytest.mark.parametrize("props", basic_modes) +def test_szng004_on_focus(test, props): + on_focus(test, props, generate_mock_data) diff --git a/components/dash-table/tests/selenium/test_sizing_y.py b/components/dash-table/tests/selenium/test_sizing_y.py new file mode 100644 index 0000000000..7a2344cab0 --- /dev/null +++ b/components/dash-table/tests/selenium/test_sizing_y.py @@ -0,0 +1,13 @@ +import pytest + +from test_sizing import on_focus + +from utils import ( + basic_modes, + generate_markdown_mock_data, +) + + +@pytest.mark.parametrize("props", basic_modes) +def test_szng005_on_focus(test, props): + on_focus(test, props, generate_markdown_mock_data) diff --git a/components/dash-table/tests/selenium/test_sizing_z.py b/components/dash-table/tests/selenium/test_sizing_z.py new file mode 100644 index 0000000000..004ad015dd --- /dev/null +++ b/components/dash-table/tests/selenium/test_sizing_z.py @@ -0,0 +1,13 @@ +import pytest + +from test_sizing import on_focus + +from utils import ( + basic_modes, + generate_mixed_markdown_data, +) + + +@pytest.mark.parametrize("props", basic_modes) +def test_szng006_on_focus(test, props): + on_focus(test, props, generate_mixed_markdown_data) diff --git a/dash/_dash_renderer.py b/dash/_dash_renderer.py index b7bdcfbccf..ce978ec74e 100644 --- a/dash/_dash_renderer.py +++ b/dash/_dash_renderer.py @@ -1,4 +1,4 @@ -__version__ = "1.11.3" +__version__ = "1.11.4" _js_dist_dependencies = [ { @@ -39,7 +39,7 @@ { "relative_package_path": "dash-renderer/build/dash_renderer.min.js", "dev_package_path": "dash-renderer/build/dash_renderer.dev.js", - "external_url": "https://unpkg.com/dash-renderer@1.11.3" + "external_url": "https://unpkg.com/dash-renderer@1.11.4" "/build/dash_renderer.min.js", "namespace": "dash", }, diff --git a/dash/_utils.py b/dash/_utils.py index 31de7e88cb..83b2895554 100644 --- a/dash/_utils.py +++ b/dash/_utils.py @@ -8,6 +8,8 @@ import logging import io import json +import secrets +import string from functools import wraps logger = logging.getLogger() @@ -206,3 +208,9 @@ def _wrapper(*args, **kwargs): return _wrapper return wrapper + + +def gen_salt(chars): + return "".join( + secrets.choice(string.ascii_letters + string.digits) for _ in range(chars) + ) diff --git a/dash/dash-renderer/package-lock.json b/dash/dash-renderer/package-lock.json index 07b3ed0b5b..b9e768168f 100644 --- a/dash/dash-renderer/package-lock.json +++ b/dash/dash-renderer/package-lock.json @@ -1,12 +1,12 @@ { "name": "dash-renderer", - "version": "1.11.3", + "version": "1.11.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "dash-renderer", - "version": "1.11.3", + "version": "1.11.4", "license": "MIT", "dependencies": { "@babel/polyfill": "^7.12.1", diff --git a/dash/dash-renderer/package.json b/dash/dash-renderer/package.json index e03100240e..57171862c6 100644 --- a/dash/dash-renderer/package.json +++ b/dash/dash-renderer/package.json @@ -1,6 +1,6 @@ { "name": "dash-renderer", - "version": "1.11.3", + "version": "1.11.4", "description": "render dash components in react", "main": "build/dash_renderer.min.js", "scripts": { diff --git a/dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.react.js b/dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.react.js index 5703add4db..49939ea1de 100644 --- a/dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.react.js +++ b/dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.react.js @@ -110,7 +110,7 @@ function UnconnectedErrorContent({error, base}) { )} {/* Backend Error */} {typeof error.html !== 'string' ? null : error.html.indexOf( - '
diff --git a/dash/dash.py b/dash/dash.py index c0b6cb410d..cc04b48b10 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -11,11 +11,12 @@ import mimetypes import hashlib import base64 +import traceback from urllib.parse import urlparse import flask from flask_compress import Compress -from werkzeug.debug.tbtools import get_current_traceback + from pkg_resources import get_distribution, parse_version from dash import dcc from dash import html @@ -48,6 +49,7 @@ patch_collections_abc, split_callback_id, to_json, + gen_salt, ) from . import _callback from . import _get_paths @@ -102,6 +104,42 @@ _re_renderer_scripts_id = 'id="_dash-renderer', "new DashRenderer" +def _get_traceback(secret, error: Exception): + + try: + # pylint: disable=import-outside-toplevel + from werkzeug.debug import tbtools + except ImportError: + tbtools = None + + def _get_skip(text, divider=2): + skip = 0 + for i, line in enumerate(text): + if "%% callback invoked %%" in line: + skip = int((i + 1) / divider) + break + return skip + + # werkzeug<2.1.0 + if hasattr(tbtools, "get_current_traceback"): + tb = tbtools.get_current_traceback() + skip = _get_skip(tb.plaintext.splitlines()) + return tbtools.get_current_traceback(skip=skip).render_full() + + if hasattr(tbtools, "DebugTraceback"): + tb = tbtools.DebugTraceback(error) # pylint: disable=no-member + skip = _get_skip(tb.render_traceback_text().splitlines()) + + # pylint: disable=no-member + return tbtools.DebugTraceback(error, skip=skip).render_debugger_html( + True, secret, True + ) + + tb = traceback.format_exception(type(error), error, error.__traceback__) + skip = _get_skip(tb, 1) + return tb[0] + "".join(tb[skip:]) + + class _NoUpdate: # pylint: disable=too-few-public-methods pass @@ -1756,19 +1794,16 @@ def enable_dev_tools( if debug and dev_tools.prune_errors: + secret = gen_salt(20) + @self.server.errorhandler(Exception) - def _wrap_errors(_): + def _wrap_errors(error): # find the callback invocation, if the error is from a callback # and skip the traceback up to that point # if the error didn't come from inside a callback, we won't # skip anything. - tb = get_current_traceback() - skip = 0 - for i, line in enumerate(tb.plaintext.splitlines()): - if "%% callback invoked %%" in line: - skip = int((i + 1) / 2) - break - return get_current_traceback(skip=skip).render_full(), 500 + tb = _get_traceback(secret, error) + return tb, 500 if debug and dev_tools.ui: diff --git a/dash/testing/application_runners.py b/dash/testing/application_runners.py index 87a7b9cb28..2a79d0373e 100644 --- a/dash/testing/application_runners.py +++ b/dash/testing/application_runners.py @@ -7,9 +7,9 @@ import subprocess import logging import inspect +import ctypes import runpy -import flask import requests from dash.testing.errors import NoAppFoundError, TestingTimeoutError, ServerCloseError @@ -102,6 +102,26 @@ def tmp_app_path(self): return self._tmp_app_path +class StoppableThread(threading.Thread): + def get_id(self): # pylint: disable=R1710 + if hasattr(self, "_thread_id"): + return self._thread_id + for thread_id, thread in threading._active.items(): # pylint: disable=W0212 + if thread is self: + return thread_id + + def kill(self): + thread_id = self.get_id() + res = ctypes.pythonapi.PyThreadState_SetAsyncExc( + ctypes.c_long(thread_id), ctypes.py_object(SystemExit) + ) + if res == 0: + raise ValueError(f"Invalid thread id: {thread_id}") + if res > 1: + ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(thread_id), None) + raise SystemExit("Stopping thread failure") + + class ThreadedRunner(BaseDashRunner): """Runs a dash application in a thread. @@ -110,25 +130,14 @@ class ThreadedRunner(BaseDashRunner): def __init__(self, keep_open=False, stop_timeout=3): super().__init__(keep_open=keep_open, stop_timeout=stop_timeout) - self.stop_route = "/_stop-{}".format(uuid.uuid4().hex) self.thread = None - @staticmethod - def _stop_server(): - # https://werkzeug.palletsprojects.com/en/0.15.x/serving/#shutting-down-the-server - stopper = flask.request.environ.get("werkzeug.server.shutdown") - if stopper is None: - raise RuntimeError("Not running with the Werkzeug Server") - stopper() - return "Flask server is shutting down" - # pylint: disable=arguments-differ def start(self, app, **kwargs): """Start the app server in threading flavor.""" - app.server.add_url_rule(self.stop_route, self.stop_route, self._stop_server) def _handle_error(): - self._stop_server() + self.stop() app.server.errorhandler(500)(_handle_error) @@ -139,9 +148,13 @@ def run(): kwargs["port"] = self.port else: self.port = kwargs["port"] - app.run_server(threaded=True, **kwargs) - self.thread = threading.Thread(target=run) + try: + app.run_server(threaded=True, **kwargs) + except SystemExit: + logger.info("Server stopped") + + self.thread = StoppableThread(target=run) self.thread.daemon = True try: self.thread.start() @@ -155,7 +168,8 @@ def run(): wait.until(lambda: self.accessible(self.url), timeout=1) def stop(self): - requests.get("{}{}".format(self.url, self.stop_route)) + self.thread.kill() + self.thread.join() wait.until_not(self.thread.is_alive, self.stop_timeout) diff --git a/dash/version.py b/dash/version.py index 55e4709070..3a5935a2d0 100644 --- a/dash/version.py +++ b/dash/version.py @@ -1 +1 @@ -__version__ = "2.3.0" +__version__ = "2.3.1" diff --git a/requires-ci.txt b/requires-ci.txt index dbeb8476c0..6106e2fafb 100644 --- a/requires-ci.txt +++ b/requires-ci.txt @@ -1,5 +1,6 @@ # Dependencies used by CI on github.com/plotly/dash black==21.6b0 +click<8.1 dash-flow-example==0.0.5 dash-dangerously-set-inner-html flake8==3.9.2