Skip to content

Commit

Permalink
Disallow duplicate component ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Aug 13, 2018
1 parent 211558c commit e190768
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
25 changes: 18 additions & 7 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,20 +843,31 @@ 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 : `{}`'.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

0 comments on commit e190768

Please sign in to comment.