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/dash.py b/dash/dash.py index 32d6ee1b22..d5142e0a03 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,23 @@ 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' + ' in the initial layout: `{}`'.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 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'