Skip to content

Deprecation notices #2985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 5, 2024
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

## Deprecated

- [#2985](https://github.com/plotly/dash/pull/2985) Deprecate dynamic component loader.
- [#2985](https://github.com/plotly/dash/pull/2985) Deprecate `run_server`, use `run` instead.
- [#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.

## [2.18.0] - 2024-09-04

## Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
from dash.exceptions import PreventUpdate
from dash import Dash, Input, Output, dcc, html
import flask
import pytest
import time


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

@app.server.route("/_logout", methods=["POST"])
def on_logout():
rep = flask.redirect("/logged-out")
rep.set_cookie("logout-cookie", "", 0)
return rep

app.layout = html.Div(
[html.H2("Logout test"), dcc.Location(id="location"), html.Div(id="content")]
)

@app.callback(Output("content", "children"), [Input("location", "pathname")])
def on_location(location_path):
if location_path is None:
raise PreventUpdate

if "logged-out" in location_path:
return "Logged out"
with pytest.warns(
DeprecationWarning,
match="The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.",
):
app.layout = [
html.H2("Logout test"),
html.Div(id="content"),
]
if add_initial_logout_button:
app.layout.append(dcc.LogoutButton())
else:

@flask.after_this_request
def _insert_cookie(rep):
rep.set_cookie("logout-cookie", "logged-in")
return rep

return dcc.LogoutButton(id="logout-btn", logout_url="/_logout")

dash_dcc.start_server(app)
time.sleep(1)
dash_dcc.percy_snapshot("Core Logout button")

assert dash_dcc.driver.get_cookie("logout-cookie")["value"] == "logged-in"

dash_dcc.wait_for_element("#logout-btn").click()
dash_dcc.wait_for_text_to_equal("#content", "Logged out")
@app.callback(Output("content", "children"), Input("content", "id"))
def on_location(location_path):
return dcc.LogoutButton(id="logout-btn", logout_url="/_logout")

assert not dash_dcc.driver.get_cookie("logout-cookie")
dash_dcc.start_server(app)
time.sleep(1)

assert dash_dcc.get_logs() == []
assert dash_dcc.get_logs() == []
5 changes: 5 additions & 0 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2256,4 +2256,9 @@ def run_server(self, *args, **kwargs):

See `app.run` for usage information.
"""
warnings.warn(
DeprecationWarning(
"Dash.run_server is deprecated and will be removed in Dash 3.0"
)
)
self.run(*args, **kwargs)
21 changes: 21 additions & 0 deletions dash/development/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
import sys
import uuid
import random
import warnings
import textwrap

from .._utils import patch_collections_abc, stringify_id, OrderedSet

MutableSequence = patch_collections_abc("MutableSequence")

rd = random.Random(0)

_deprecated_components = {
"dash_core_components": {
"LogoutButton": textwrap.dedent(
"""
The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.
eg: html.A(href=os.getenv('DASH_LOGOUT_URL'))
"""
)
}
}


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

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

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

def _validate_deprecation(self):
_type = getattr(self, "_type", "")
_ns = getattr(self, "_namespace", "")
deprecation_message = _deprecated_components.get(_ns, {}).get(_type)
if deprecation_message:
warnings.warn(DeprecationWarning(textwrap.dedent(deprecation_message)))


def _explicitize_args(func):
# Python 2
Expand Down
10 changes: 9 additions & 1 deletion dash/development/component_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import collections
import json
import os
import warnings


from ._py_components_generation import (
generate_class_file,
Expand Down Expand Up @@ -34,7 +36,13 @@ def load_components(metadata_path, namespace="default_namespace"):
components -- a list of component objects with keys
`type`, `valid_kwargs`, and `setup`.
"""

warnings.warn(
DeprecationWarning(
"Dynamic components loading has been deprecated and will be removed"
" in dash 3.0.\n"
f"Update {namespace} to generate components with dash-generate-components"
)
)
# Register the component lib for index include.
ComponentRegistry.registry.add(namespace)
components = []
Expand Down