Skip to content

Commit

Permalink
Merge pull request #1549 from getredash/change_tracking
Browse files Browse the repository at this point in the history
Change: disable version counter for queries:
  • Loading branch information
arikfr authored Jan 26, 2017
2 parents 84aba70 + 6cf1c1c commit ff28b75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
21 changes: 4 additions & 17 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def should_schedule_next(previous_iteration, now, schedule):

class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):
id = Column(db.Integer, primary_key=True)
version = Column(db.Integer)
version = Column(db.Integer, default=1)
org_id = Column(db.Integer, db.ForeignKey('organizations.id'))
org = db.relationship(Organization, backref="queries")
data_source_id = Column(db.Integer, db.ForeignKey("data_sources.id"), nullable=True)
Expand All @@ -687,8 +687,9 @@ class Query(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model):

__tablename__ = 'queries'
__mapper_args__ = {
"version_id_col": version
}
"version_id_col": version,
'version_id_generator': False
}

def to_dict(self, with_stats=False, with_visualizations=False, with_user=True, with_last_modified_by=True):
d = {
Expand Down Expand Up @@ -863,20 +864,6 @@ def fork(self, user):
db.session.add(forked_query)
return forked_query

def update_instance_tracked(self, changing_user, old_object=None, *args, **kwargs):
self.version += 1
self.update_instance(*args, **kwargs)
# save Change record
new_change = Change.save_change(user=changing_user, old_object=old_object, new_object=self)
return new_change

def tracked_save(self, changing_user, old_object=None, *args, **kwargs):
self.version += 1
self.save(*args, **kwargs)
# save Change record
new_change = Change.save_change(user=changing_user, old_object=old_object, new_object=self)
return new_change

@property
def runtime(self):
return self.latest_query_data.runtime
Expand Down
3 changes: 2 additions & 1 deletion tests/models/test_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def test_properly_log_modification(self):
change = Change.last_change(obj)

self.assertIsNotNone(change)
self.assertEqual(change.object_version, 2)
# TODO: https://github.com/getredash/redash/issues/1550
# self.assertEqual(change.object_version, 2)
self.assertEqual(change.object_version, obj.version)
self.assertIn('name', change.change)
self.assertIn('description', change.change)
Expand Down

0 comments on commit ff28b75

Please sign in to comment.