Skip to content

Commit 267cccd

Browse files
authored
Merge pull request #3195 from plotly/upgrade-get
Change to use GET request when requesting dash version from server
2 parents f0f18bf + b2d1856 commit 267cccd

File tree

7 files changed

+82
-29
lines changed

7 files changed

+82
-29
lines changed

components/dash-table/tests/selenium/test_header.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_head005_no_warnings_emitted(test):
136136
use_reloader=False,
137137
use_debugger=True,
138138
dev_tools_hot_reload=False,
139+
dev_tools_disable_version_check=True,
139140
)
140141

141142
target = test.table("table")
@@ -173,6 +174,7 @@ def test_head006_style_merged_columns(test):
173174
use_reloader=False,
174175
use_debugger=True,
175176
dev_tools_hot_reload=False,
177+
dev_tools_disable_version_check=True,
176178
)
177179

178180
target = test.table("table")

dash/_configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def load_dash_env_vars():
2929
"DASH_HOT_RELOAD_WATCH_INTERVAL",
3030
"DASH_HOT_RELOAD_MAX_RETRY",
3131
"DASH_SILENCE_ROUTES_LOGGING",
32+
"DASH_DISABLE_VERSION_CHECK",
3233
"DASH_PRUNE_ERRORS",
3334
"DASH_COMPRESS",
3435
"HOST",

dash/dash-renderer/src/components/error/menu/VersionInfo.react.js

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,17 @@ async function requestDashVersionInfo(config) {
4646
version: JSON.parse(cachedVersionInfo),
4747
link: cachedNewDashVersionLink
4848
};
49-
} else {
50-
return fetch(dashVersionUrl, {
51-
method: 'POST',
52-
body: JSON.stringify({
53-
dash_version: currentDashVersion,
54-
python_version: pythonVersion,
55-
ddk_version: ddkVersion,
56-
plotly_version: plotlyVersion
57-
}),
58-
headers: {
59-
'Content-Type': 'application/json'
60-
}
61-
})
49+
} else if (shouldRequestDashVersion(config)) {
50+
const queryParams = new URLSearchParams({
51+
dash_version: currentDashVersion,
52+
python_version: pythonVersion,
53+
ddk_version: ddkVersion,
54+
plotly_version: plotlyVersion
55+
}).toString();
56+
return fetch(dashVersionUrl + '?' + queryParams, {mode: 'cors'})
6257
.then(response => response.json())
63-
.catch(() => {
64-
return {};
65-
})
6658
.then(body => {
67-
if (body.version && body.link) {
59+
if (body && body.version && body.link) {
6860
localStorage.setItem(
6961
'cachedNewDashVersion',
7062
JSON.stringify(body.version)
@@ -75,18 +67,42 @@ async function requestDashVersionInfo(config) {
7567
} else {
7668
return {};
7769
}
70+
})
71+
.catch(() => {
72+
return {};
7873
});
7974
}
8075
}
8176

82-
function shouldShowUpgradeNotification(currentDashVersion, newDashVersion) {
83-
const showNotifications = localStorage.getItem('showNotifications');
77+
function shouldRequestDashVersion(config) {
78+
const showNotificationsLocalStorage =
79+
localStorage.getItem('showNotifications');
80+
const showNotifications = config.disable_version_check
81+
? false
82+
: showNotificationsLocalStorage !== 'false';
83+
const lastFetched = localStorage.getItem('lastFetched');
84+
return (
85+
showNotifications &&
86+
(!lastFetched || Date.now() - Number(lastFetched) > DAY_IN_MS)
87+
);
88+
}
89+
90+
function shouldShowUpgradeNotification(
91+
currentDashVersion,
92+
newDashVersion,
93+
config
94+
) {
95+
const showNotificationsLocalStorage =
96+
localStorage.getItem('showNotifications');
97+
const showNotifications = config.disable_version_check
98+
? false
99+
: showNotificationsLocalStorage !== 'false';
84100
const lastDismissed = localStorage.getItem('lastDismissed');
85101
const lastDismissedVersion = localStorage.getItem('lastDismissedVersion');
86102
if (
87103
newDashVersion === undefined ||
88104
compareVersions(currentDashVersion, newDashVersion) >= 0 ||
89-
showNotifications === 'false'
105+
!showNotifications
90106
) {
91107
return false;
92108
} else if (
@@ -133,8 +149,10 @@ export const VersionInfo = ({config}) => {
133149

134150
useEffect(() => {
135151
requestDashVersionInfo(config).then(body => {
136-
setNewDashVersionLink(body.link);
137-
setNewDashVersion(body.version);
152+
if (body) {
153+
setNewDashVersionLink(body.link);
154+
setNewDashVersion(body.version);
155+
}
138156
});
139157
}, []);
140158

@@ -178,7 +196,8 @@ export const VersionInfo = ({config}) => {
178196
<span>v{config.dash_version}</span>
179197
{shouldShowUpgradeNotification(
180198
config.dash_version,
181-
newDashVersion
199+
newDashVersion,
200+
config
182201
) ? (
183202
<button
184203
className='dash-debug-menu__upgrade-button'

dash/dash.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ def _config(self):
802802
"requests_pathname_prefix": self.config.requests_pathname_prefix,
803803
"ui": self._dev_tools.ui,
804804
"props_check": self._dev_tools.props_check,
805+
"disable_version_check": self._dev_tools.disable_version_check,
805806
"show_undo_redo": self.config.show_undo_redo,
806807
"suppress_callback_exceptions": self.config.suppress_callback_exceptions,
807808
"update_title": self.config.update_title,
@@ -1754,6 +1755,12 @@ def _setup_dev_tools(self, **kwargs):
17541755
get_combined_config(attr, kwargs.get(attr, None), default=default)
17551756
)
17561757

1758+
dev_tools["disable_version_check"] = get_combined_config(
1759+
"disable_version_check",
1760+
kwargs.get("disable_version_check", None),
1761+
default=False,
1762+
)
1763+
17571764
return dev_tools
17581765

17591766
def enable_dev_tools(
@@ -1767,6 +1774,7 @@ def enable_dev_tools(
17671774
dev_tools_hot_reload_watch_interval=None,
17681775
dev_tools_hot_reload_max_retry=None,
17691776
dev_tools_silence_routes_logging=None,
1777+
dev_tools_disable_version_check=None,
17701778
dev_tools_prune_errors=None,
17711779
):
17721780
"""Activate the dev tools, called by `run`. If your application
@@ -1787,6 +1795,7 @@ def enable_dev_tools(
17871795
- DASH_HOT_RELOAD_WATCH_INTERVAL
17881796
- DASH_HOT_RELOAD_MAX_RETRY
17891797
- DASH_SILENCE_ROUTES_LOGGING
1798+
- DASH_DISABLE_VERSION_CHECK
17901799
- DASH_PRUNE_ERRORS
17911800
17921801
:param debug: Enable/disable all the dev tools unless overridden by the
@@ -1832,6 +1841,11 @@ def enable_dev_tools(
18321841
env: ``DASH_SILENCE_ROUTES_LOGGING``
18331842
:type dev_tools_silence_routes_logging: bool
18341843
1844+
:param dev_tools_disable_version_check: Silence the upgrade
1845+
notification to prevent making requests to the Dash server.
1846+
env: ``DASH_DISABLE_VERSION_CHECK``
1847+
:type dev_tools_disable_version_check: bool
1848+
18351849
:param dev_tools_prune_errors: Reduce tracebacks to just user code,
18361850
stripping out Flask and Dash pieces. Only available with debugging.
18371851
`True` by default, set to `False` to see the complete traceback.
@@ -1853,6 +1867,7 @@ def enable_dev_tools(
18531867
hot_reload_watch_interval=dev_tools_hot_reload_watch_interval,
18541868
hot_reload_max_retry=dev_tools_hot_reload_max_retry,
18551869
silence_routes_logging=dev_tools_silence_routes_logging,
1870+
disable_version_check=dev_tools_disable_version_check,
18561871
prune_errors=dev_tools_prune_errors,
18571872
)
18581873

@@ -2052,6 +2067,7 @@ def run(
20522067
dev_tools_hot_reload_watch_interval: Optional[int] = None,
20532068
dev_tools_hot_reload_max_retry: Optional[int] = None,
20542069
dev_tools_silence_routes_logging: Optional[bool] = None,
2070+
dev_tools_disable_version_check: Optional[bool] = None,
20552071
dev_tools_prune_errors: Optional[bool] = None,
20562072
**flask_run_options,
20572073
):
@@ -2124,6 +2140,11 @@ def run(
21242140
env: ``DASH_SILENCE_ROUTES_LOGGING``
21252141
:type dev_tools_silence_routes_logging: bool
21262142
2143+
:param dev_tools_disable_version_check: Silence the upgrade
2144+
notification to prevent making requests to the Dash server.
2145+
env: ``DASH_DISABLE_VERSION_CHECK``
2146+
:type dev_tools_disable_version_check: bool
2147+
21272148
:param dev_tools_prune_errors: Reduce tracebacks to just user code,
21282149
stripping out Flask and Dash pieces. Only available with debugging.
21292150
`True` by default, set to `False` to see the complete traceback.
@@ -2161,6 +2182,7 @@ def run(
21612182
dev_tools_hot_reload_watch_interval,
21622183
dev_tools_hot_reload_max_retry,
21632184
dev_tools_silence_routes_logging,
2185+
dev_tools_disable_version_check,
21642186
dev_tools_prune_errors,
21652187
)
21662188

dash/testing/application_runners.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def run():
162162
app.css.config.serve_locally = True
163163

164164
options = kwargs.copy()
165+
options["dev_tools_disable_version_check"] = True
165166

166167
if "port" not in kwargs:
167168
options["port"] = self.port = BaseDashRunner._next_port

tests/integration/callbacks/test_missing_outputs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
from dash.testing.wait import until
1010

1111
debugging = dict(
12-
debug=True, use_reloader=False, use_debugger=True, dev_tools_hot_reload=False
12+
debug=True,
13+
use_reloader=False,
14+
use_debugger=True,
15+
dev_tools_hot_reload=False,
16+
dev_tools_disable_version_check=True,
1317
)
1418

1519

@@ -63,7 +67,7 @@ def content_inner(n2):
6367
def out2(contents):
6468
return sum(contents)
6569

66-
dash_duo.start_server(app)
70+
dash_duo.start_server(app, dev_tools_disable_version_check=True)
6771

6872
dash_duo.wait_for_text_to_equal("#content", "")
6973
dash_duo.wait_for_text_to_equal("#output", "0")
@@ -231,7 +235,7 @@ def content_inner(n2):
231235
def out2(ci, cj):
232236
return sum(ci) + sum(cj)
233237

234-
dash_duo.start_server(app)
238+
dash_duo.start_server(app, dev_tools_disable_version_check=True)
235239

236240
dash_duo.wait_for_text_to_equal("#content1", "0\n0")
237241
dash_duo.wait_for_text_to_equal("#content2", "")
@@ -304,7 +308,7 @@ def this_callback_takes_forever(n_clicks):
304308
call_counts["button-output"].value += 1
305309
return "New value!"
306310

307-
dash_duo.start_server(app)
311+
dash_duo.start_server(app, dev_tools_disable_version_check=True)
308312

309313
dash_duo.wait_for_text_to_equal("#ch1-title", "Chapter 1")
310314
assert call_counts["body"].value == 1

tests/integration/devtools/test_devtools_ui.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def test_dvui001_disable_props_check_config(dash_duo):
2424
use_debugger=True,
2525
dev_tools_hot_reload=False,
2626
dev_tools_props_check=False,
27+
dev_tools_disable_version_check=True,
2728
)
2829

2930
dash_duo.wait_for_text_to_equal("#tcid", "Hello Props Check")
@@ -48,6 +49,7 @@ def test_dvui002_disable_ui_config(dash_duo):
4849
use_debugger=True,
4950
dev_tools_hot_reload=False,
5051
dev_tools_ui=False,
52+
dev_tools_disable_version_check=True,
5153
)
5254

5355
dash_duo.wait_for_text_to_equal("#tcid", "Hello Disable UI")
@@ -70,6 +72,7 @@ def test_dvui003_callback_graph(dash_duo):
7072
use_reloader=False,
7173
use_debugger=True,
7274
dev_tools_hot_reload=False,
75+
dev_tools_disable_version_check=True,
7376
)
7477

7578
dash_duo.wait_for_text_to_equal("#totals", "0 of 0 items completed")
@@ -137,6 +140,7 @@ def get_width(n_clicks):
137140
use_reloader=False,
138141
use_debugger=True,
139142
dev_tools_hot_reload=False,
143+
dev_tools_disable_version_check=True,
140144
)
141145

142146
dash_duo.find_element("#dash-debug-menu__callback-graph-button").click()
@@ -172,7 +176,7 @@ def check_undo_redo_exist(has_undo, has_redo):
172176
def set_b(a):
173177
return a
174178

175-
dash_duo.start_server(app)
179+
dash_duo.start_server(app, dev_tools_disable_version_check=True)
176180

177181
dash_duo.find_element("#a").send_keys("xyz")
178182

@@ -207,7 +211,7 @@ def test_dvui006_no_undo_redo(dash_duo):
207211
def set_b(a):
208212
return a
209213

210-
dash_duo.start_server(app)
214+
dash_duo.start_server(app, dev_tools_disable_version_check=True)
211215

212216
dash_duo.find_element("#a").send_keys("xyz")
213217

0 commit comments

Comments
 (0)