Skip to content

Commit

Permalink
Workaround for cases when widget is missing but referenced in a dashb…
Browse files Browse the repository at this point in the history
…oard layout (re. getredash#120)
  • Loading branch information
arikfr committed Apr 29, 2014
1 parent 48cac8a commit 5e65bed
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,23 @@ def to_dict(self, with_widgets=False):
.switch(Query)\
.join(QueryResult, join_type=peewee.JOIN_LEFT_OUTER)
widgets = {w.id: w.to_dict() for w in widgets}
widgets_layout = map(lambda row: map(lambda widget_id: widgets.get(widget_id, None), row), layout)

# The following is a workaround for cases when the widget object gets deleted without the dashboard layout
# updated. This happens for users with old databases that didn't have a foreign key relationship between
# visualizations and widgets.
# It's temporary until better solution is implemented (we probably should move the position information
# to the widget).
widgets_layout = []
for row in layout:
new_row = []
for widget_id in row:
widget = widgets.get(widget_id, None)
if widget:
new_row.append(widget)

widgets_layout.append(new_row)

# widgets_layout = map(lambda row: map(lambda widget_id: widgets.get(widget_id, None), row), layout)
else:
widgets_layout = None

Expand Down

0 comments on commit 5e65bed

Please sign in to comment.