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

Fix: remove widgets when deleting a visualization. #3423

Merged
merged 3 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def copy(self):
class Widget(TimestampMixin, BelongsToOrgMixin, db.Model):
id = Column(db.Integer, primary_key=True)
visualization_id = Column(db.Integer, db.ForeignKey('visualizations.id'), nullable=True)
visualization = db.relationship(Visualization, backref='widgets')
visualization = db.relationship(Visualization, backref=backref('widgets', cascade='delete'))
text = Column(db.Text, nullable=True)
width = Column(db.Integer)
options = Column(db.Text)
Expand Down
8 changes: 8 additions & 0 deletions tests/handlers/test_visualizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@ def test_only_owner_collaborator_or_admin_can_delete_visualization(self):

rv = self.make_request('delete', path, user=admin_from_diff_org)
self.assertEquals(rv.status_code, 404)

def test_deleting_a_visualization_deletes_dashboard_widgets(self):
vis = self.factory.create_visualization()
widget = self.factory.create_widget(visualization=vis)

rv = self.make_request('delete', '/api/visualizations/{}'.format(vis.id))

self.assertIsNone(models.Widget.query.filter(models.Widget.id == widget.id).first())