Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow duplicate component ids. #320

Merged
merged 3 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Disallow duplicate component ids.
  • Loading branch information
T4rk1n committed Aug 13, 2018
commit e190768d7ae3db400e744d6d1d594969aacd2bf9
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