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

Change: disable version counter for queries: #1549

Merged
merged 4 commits into from
Jan 26, 2017
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
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