From e190768d7ae3db400e744d6d1d594969aacd2bf9 Mon Sep 17 00:00:00 2001 From: Philippe Duval Date: Tue, 31 Jul 2018 13:31:10 -0400 Subject: [PATCH 1/3] Disallow duplicate component ids. --- dash/dash.py | 25 ++++++++++++++++++------- dash/exceptions.py | 4 ++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 32d6ee1b22..84bad37263 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -843,13 +843,8 @@ def dispatch(self): return self.callback_map[target_id]['callback'](*args) - def _setup_server(self): - if self.config.include_assets_files: - self._walk_assets_directory() - - # Make sure `layout` is set before running the server - value = getattr(self, 'layout') - if value is None: + def _validate_layout(self): + if self.layout is None: raise exceptions.NoLayoutException( '' 'The layout was `None` ' @@ -857,6 +852,22 @@ def _setup_server(self): 'Make sure to set the `layout` attribute of your application ' 'before running the server.') + layout_id = getattr(self.layout, 'id', None) + + component_ids = {layout_id} if layout_id else set() + for component in self.layout.traverse(): + component_id = getattr(component, 'id', None) + if component_id and component_id in component_ids: + raise exceptions.DuplicateIdError( + 'Duplicate component id found : `{}`'.format(component_id)) + component_ids.add(component_id) + + def _setup_server(self): + if self.config.include_assets_files: + self._walk_assets_directory() + + self._validate_layout() + self._generate_scripts_html() self._generate_css_dist_html() diff --git a/dash/exceptions.py b/dash/exceptions.py index c459b0e5c2..58cf322715 100644 --- a/dash/exceptions.py +++ b/dash/exceptions.py @@ -50,5 +50,9 @@ class PreventUpdate(CallbackException): pass +class DuplicateIdError(DashException): + pass + + class InvalidCallbackReturnValue(CallbackException): pass From f591ae59b4e5a31552ba2b83a199cb6f1e544668 Mon Sep 17 00:00:00 2001 From: Philippe Duval Date: Thu, 9 Aug 2018 15:00:25 -0400 Subject: [PATCH 2/3] Specify duplicate component id in initial layout. --- dash/dash.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index 84bad37263..d5142e0a03 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -859,7 +859,8 @@ def _validate_layout(self): component_id = getattr(component, 'id', None) if component_id and component_id in component_ids: raise exceptions.DuplicateIdError( - 'Duplicate component id found : `{}`'.format(component_id)) + 'Duplicate component id found' + ' in the initial layout: `{}`'.format(component_id)) component_ids.add(component_id) def _setup_server(self): From 2d8a0334089904e172d6b735c4017c47d85ae40e Mon Sep 17 00:00:00 2001 From: Philippe Duval Date: Mon, 13 Aug 2018 12:41:53 -0400 Subject: [PATCH 3/3] Update version and CHANGELOG.md --- CHANGELOG.md | 3 +++ dash/version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8a66948e2..18cb569800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.24.2 - 2018-08-13 +## Fixed +- Disallow duplicate component ids in the initial layout. [#320](https://github.com/plotly/dash/pull/320) ## 0.24.1 - 2018-08-10 ## Fixed diff --git a/dash/version.py b/dash/version.py index 7fe14931d2..d1d123f305 100644 --- a/dash/version.py +++ b/dash/version.py @@ -1 +1 @@ -__version__ = '0.24.1' +__version__ = '0.24.2'