Skip to content

Commit 1b4787d

Browse files
committed
Add silence_upgrade_notification flag to prevent upgrade notification requests in CI
1 parent 41c3de9 commit 1b4787d

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

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_SILENCE_UPGRADE_NOTIFICATION",
3233
"DASH_PRUNE_ERRORS",
3334
"DASH_COMPRESS",
3435
"HOST",

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ async function requestDashVersionInfo(config) {
3232
ddk_version: ddkVersion,
3333
plotly_version: plotlyVersion
3434
} = config;
35+
if (!shouldRequestDashVersion(config)) {
36+
return {};
37+
}
3538
const cachedVersionInfo = localStorage.getItem('cachedNewDashVersion');
3639
const cachedNewDashVersionLink = localStorage.getItem(
3740
'cachedNewDashVersionLink'
@@ -74,14 +77,35 @@ async function requestDashVersionInfo(config) {
7477
}
7578
}
7679

77-
function shouldShowUpgradeNotification(currentDashVersion, newDashVersion) {
78-
const showNotifications = localStorage.getItem('showNotifications');
80+
function shouldRequestDashVersion(config) {
81+
const showNotificationsLocalStorage =
82+
localStorage.getItem('showNotifications');
83+
const showNotifications = config.silence_upgrade_notification
84+
? false
85+
: showNotificationsLocalStorage !== 'false';
86+
const lastFetched = localStorage.getItem('lastFetched');
87+
return (
88+
showNotifications &&
89+
(!lastFetched || Date.now() - Number(lastFetched) > DAY_IN_MS)
90+
);
91+
}
92+
93+
function shouldShowUpgradeNotification(
94+
currentDashVersion,
95+
newDashVersion,
96+
config
97+
) {
98+
const showNotificationsLocalStorage =
99+
localStorage.getItem('showNotifications');
100+
const showNotifications = config.silence_upgrade_notification
101+
? false
102+
: showNotificationsLocalStorage !== 'false';
79103
const lastDismissed = localStorage.getItem('lastDismissed');
80104
const lastDismissedVersion = localStorage.getItem('lastDismissedVersion');
81105
if (
82106
newDashVersion === undefined ||
83107
compareVersions(currentDashVersion, newDashVersion) >= 0 ||
84-
showNotifications === 'false'
108+
!showNotifications
85109
) {
86110
return false;
87111
} else if (
@@ -173,7 +197,8 @@ export const VersionInfo = ({config}) => {
173197
<span>v{config.dash_version}</span>
174198
{shouldShowUpgradeNotification(
175199
config.dash_version,
176-
newDashVersion
200+
newDashVersion,
201+
config
177202
) ? (
178203
<button
179204
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+
"silence_upgrade_notification": self._dev_tools.silence_upgrade_notification,
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["silence_upgrade_notification"] = get_combined_config(
1759+
"silence_upgrade_notification",
1760+
kwargs.get("silence_upgrade_notification", 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_silence_upgrade_notification=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_SILENCE_UPGRADE_NOTIFICATION
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_silence_upgrade_notification: Silence the upgrade
1845+
notification to prevent making requests to the Dash server.
1846+
env: ``DASH_SILENCE_UPGRADE_NOTIFICATION``
1847+
:type dev_tools_silence_upgrade_notification: 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+
silence_upgrade_notification=dev_tools_silence_upgrade_notification,
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_silence_upgrade_notification: 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_silence_upgrade_notification: Silence the upgrade
2144+
notification to prevent making requests to the Dash server.
2145+
env: ``DASH_SILENCE_UPGRADE_NOTIFICATION``
2146+
:type dev_tools_silence_upgrade_notification: 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_silence_upgrade_notification,
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["silence_upgrade_notification"] = True
165166

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

0 commit comments

Comments
 (0)