Skip to content

Commit 6545710

Browse files
authored
Merge pull request #2985 from plotly/deprecation
Deprecation notices
2 parents dea1c62 + e6b0c36 commit 6545710

File tree

5 files changed

+63
-38
lines changed

5 files changed

+63
-38
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
All notable changes to `dash` will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

5+
## [UNRELEASED]
6+
7+
## Deprecated
8+
9+
- [#2985](https://github.com/plotly/dash/pull/2985) Deprecate dynamic component loader.
10+
- [#2985](https://github.com/plotly/dash/pull/2985) Deprecate `run_server`, use `run` instead.
11+
- [#2899](https://github.com/plotly/dash/pull/2899) Deprecate `dcc.LogoutButton`, can be replaced with a `html.Button` or `html.A`. eg: `html.A(href=os.getenv('DASH_LOGOUT_URL'))` on a Dash Enterprise instance.
12+
513
## [2.18.0] - 2024-09-04
614

715
## Added
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
1-
from dash.exceptions import PreventUpdate
21
from dash import Dash, Input, Output, dcc, html
3-
import flask
2+
import pytest
43
import time
54

65

7-
def test_llgo001_location_logout(dash_dcc):
6+
@pytest.mark.parametrize("add_initial_logout_button", [False, True])
7+
def test_llgo001_location_logout(dash_dcc, add_initial_logout_button):
8+
# FIXME: Logout button is deprecated, remove this test for dash 3.0
89
app = Dash(__name__)
910

10-
@app.server.route("/_logout", methods=["POST"])
11-
def on_logout():
12-
rep = flask.redirect("/logged-out")
13-
rep.set_cookie("logout-cookie", "", 0)
14-
return rep
15-
16-
app.layout = html.Div(
17-
[html.H2("Logout test"), dcc.Location(id="location"), html.Div(id="content")]
18-
)
19-
20-
@app.callback(Output("content", "children"), [Input("location", "pathname")])
21-
def on_location(location_path):
22-
if location_path is None:
23-
raise PreventUpdate
24-
25-
if "logged-out" in location_path:
26-
return "Logged out"
11+
with pytest.warns(
12+
DeprecationWarning,
13+
match="The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.",
14+
):
15+
app.layout = [
16+
html.H2("Logout test"),
17+
html.Div(id="content"),
18+
]
19+
if add_initial_logout_button:
20+
app.layout.append(dcc.LogoutButton())
2721
else:
2822

29-
@flask.after_this_request
30-
def _insert_cookie(rep):
31-
rep.set_cookie("logout-cookie", "logged-in")
32-
return rep
33-
34-
return dcc.LogoutButton(id="logout-btn", logout_url="/_logout")
35-
36-
dash_dcc.start_server(app)
37-
time.sleep(1)
38-
dash_dcc.percy_snapshot("Core Logout button")
39-
40-
assert dash_dcc.driver.get_cookie("logout-cookie")["value"] == "logged-in"
41-
42-
dash_dcc.wait_for_element("#logout-btn").click()
43-
dash_dcc.wait_for_text_to_equal("#content", "Logged out")
23+
@app.callback(Output("content", "children"), Input("content", "id"))
24+
def on_location(location_path):
25+
return dcc.LogoutButton(id="logout-btn", logout_url="/_logout")
4426

45-
assert not dash_dcc.driver.get_cookie("logout-cookie")
27+
dash_dcc.start_server(app)
28+
time.sleep(1)
4629

47-
assert dash_dcc.get_logs() == []
30+
assert dash_dcc.get_logs() == []

Diff for: dash/dash.py

+5
Original file line numberDiff line numberDiff line change
@@ -2256,4 +2256,9 @@ def run_server(self, *args, **kwargs):
22562256
22572257
See `app.run` for usage information.
22582258
"""
2259+
warnings.warn(
2260+
DeprecationWarning(
2261+
"Dash.run_server is deprecated and will be removed in Dash 3.0"
2262+
)
2263+
)
22592264
self.run(*args, **kwargs)

Diff for: dash/development/base_component.py

+21
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44
import sys
55
import uuid
66
import random
7+
import warnings
8+
import textwrap
79

810
from .._utils import patch_collections_abc, stringify_id, OrderedSet
911

1012
MutableSequence = patch_collections_abc("MutableSequence")
1113

1214
rd = random.Random(0)
1315

16+
_deprecated_components = {
17+
"dash_core_components": {
18+
"LogoutButton": textwrap.dedent(
19+
"""
20+
The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.
21+
eg: html.A(href=os.getenv('DASH_LOGOUT_URL'))
22+
"""
23+
)
24+
}
25+
}
26+
1427

1528
# pylint: disable=no-init,too-few-public-methods
1629
class ComponentRegistry:
@@ -95,6 +108,7 @@ def __str__(self):
95108
REQUIRED = _REQUIRED()
96109

97110
def __init__(self, **kwargs):
111+
self._validate_deprecation()
98112
import dash # pylint: disable=import-outside-toplevel, cyclic-import
99113

100114
# pylint: disable=super-init-not-called
@@ -405,6 +419,13 @@ def __repr__(self):
405419
props_string = repr(getattr(self, "children", None))
406420
return f"{self._type}({props_string})"
407421

422+
def _validate_deprecation(self):
423+
_type = getattr(self, "_type", "")
424+
_ns = getattr(self, "_namespace", "")
425+
deprecation_message = _deprecated_components.get(_ns, {}).get(_type)
426+
if deprecation_message:
427+
warnings.warn(DeprecationWarning(textwrap.dedent(deprecation_message)))
428+
408429

409430
def _explicitize_args(func):
410431
# Python 2

Diff for: dash/development/component_loader.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import collections
22
import json
33
import os
4+
import warnings
5+
46

57
from ._py_components_generation import (
68
generate_class_file,
@@ -34,7 +36,13 @@ def load_components(metadata_path, namespace="default_namespace"):
3436
components -- a list of component objects with keys
3537
`type`, `valid_kwargs`, and `setup`.
3638
"""
37-
39+
warnings.warn(
40+
DeprecationWarning(
41+
"Dynamic components loading has been deprecated and will be removed"
42+
" in dash 3.0.\n"
43+
f"Update {namespace} to generate components with dash-generate-components"
44+
)
45+
)
3846
# Register the component lib for index include.
3947
ComponentRegistry.registry.add(namespace)
4048
components = []

0 commit comments

Comments
 (0)