Skip to content

Commit

Permalink
Refactors deprecated_types to deprecated_components
Browse files Browse the repository at this point in the history
- Checks for namespace on top of the type
- Modifies warning message
- Modifies test to capture new warning message
  • Loading branch information
leeagustin committed Jun 28, 2024
1 parent c54ae91 commit 87385a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _insert_cookie(rep):

with pytest.warns(
DeprecationWarning,
match="LogoutButton is deprecated, use a different component type instead",
match="The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A.",
):
dash_dcc.start_server(app)
time.sleep(1)
Expand Down
21 changes: 14 additions & 7 deletions dash/_validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from collections import defaultdict
from collections.abc import MutableSequence
import re
import warnings
Expand Down Expand Up @@ -424,13 +425,19 @@ def validate_layout(layout, layout_value):

def _validate(value):
def _validate_type(comp):
deprecated_types = ["LogoutButton"]
component_type = getattr(comp, "_type", None)
if component_type and component_type in deprecated_types:
warnings.warn(
f"{component_type} is deprecated, use a different component type instead",
DeprecationWarning,
)
deprecated_components = defaultdict(lambda: defaultdict(dict))
deprecated_components["dash_core_components"][
"LogoutButton"
] = """
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'))
"""

_type = getattr(comp, "_type", "")
_ns = getattr(comp, "_namespace", "")
deprecation_message = deprecated_components[_ns][_type]
if deprecation_message:
warnings.warn(dedent(deprecation_message), DeprecationWarning)

def _validate_id(comp):
component_id = stringify_id(getattr(comp, "id", None))
Expand Down

0 comments on commit 87385a9

Please sign in to comment.