From 5b51e6c0f936eab32b93812774b5e3e5ecfb1abb Mon Sep 17 00:00:00 2001 From: emilhe Date: Tue, 5 Mar 2024 18:06:13 +0100 Subject: [PATCH] Preparing 1.0.14 release --- CHANGELOG.md | 5 ++++- dash_extensions/validate.py | 29 +++++++++++++++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- poetry.lock | 2 +- pyproject.toml | 2 +- 6 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 dash_extensions/validate.py diff --git a/CHANGELOG.md b/CHANGELOG.md index fcaad35..55ee54a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,15 @@ All notable changes to this project will be documented in this file. +## [1.0.14] - 05-03-24 + +- Add new `validate` module, which adds an `assert_no_random_ids` that assets that Dash didn't generate any random component ids + ## [1.0.13] - 05-03-24 ### Added - Add new `pages` module, which introduces the `page components` and `page properties` concepts -- Add new `validate` module, which adds an `assert_no_random_ids` that assets that Dash didn't generate any random component ids ## [1.0.12] - 04-02-23 diff --git a/dash_extensions/validate.py b/dash_extensions/validate.py new file mode 100644 index 0000000..df5cc5b --- /dev/null +++ b/dash_extensions/validate.py @@ -0,0 +1,29 @@ +import dash.dependencies + +# region Random component id generation + +_set_random_id = dash.development.base_component.Component._set_random_id +_components_with_random_ids = [] + + +def _collect_components_with_random_ids(self): + if not hasattr(self, "id"): + _components_with_random_ids.append(self) + return _set_random_id(self) + + +dash.development.base_component.Component._set_random_id = _collect_components_with_random_ids + + +def assert_no_random_ids(): + """ + When a component is referenced in a callback, a random id is assigned automatically, if an id is not already set. + This operation makes the application _stateful_, which is *not* recommended. This function raises an assertion + error if any components have been assigned random ids, thereby forcing the developer to set ids for all components. + """ + if _components_with_random_ids: + return + raise AssertionError( + f"The following components have random ids: {', '.join([str(c) for c in _components_with_random_ids])}") + +# endregion diff --git a/package-lock.json b/package-lock.json index ef6a443..42dce3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "dash-extensions", - "version": "1.0.13", + "version": "1.0.14", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package.json b/package.json index c5e92bd..aad8df8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dash-extensions", - "version": "1.0.13", + "version": "1.0.14", "description": "Extensions for Plotly Dash.", "main": "build/index.js", "scripts": { diff --git a/poetry.lock b/poetry.lock index 9cfe0b0..7c4588b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1246,8 +1246,8 @@ files = [ [package.dependencies] numpy = [ {version = ">=1.20.3", markers = "python_version < \"3.10\""}, - {version = ">=1.21.0", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, {version = ">=1.23.2", markers = "python_version >= \"3.11\""}, + {version = ">=1.21.0", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, ] python-dateutil = ">=2.8.2" pytz = ">=2020.1" diff --git a/pyproject.toml b/pyproject.toml index a254fa4..4b0f002 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dash-extensions" -version = "1.0.13" +version = "1.0.14" description = "Extensions for Plotly Dash." authors = ["emher "] license = "MIT"