Skip to content

Commit

Permalink
Merge pull request #320 from plotly/duplicate-component-ids
Browse files Browse the repository at this point in the history
Disallow duplicate component ids.
  • Loading branch information
T4rk1n authored Aug 13, 2018
2 parents 211558c + 2d8a033 commit a5b7592
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 19 additions & 7 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,20 +843,32 @@ 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` '
'at the time that `run_server` was called. '
'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()

Expand Down
4 changes: 4 additions & 0 deletions dash/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ class PreventUpdate(CallbackException):
pass


class DuplicateIdError(DashException):
pass


class InvalidCallbackReturnValue(CallbackException):
pass
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.24.1'
__version__ = '0.24.2'

0 comments on commit a5b7592

Please sign in to comment.