{"action":"created","comment":{"url":"https://api.github.com/repos/getredash/redash/pulls/comments/234204845","pull_request_review_id":175789877,"id":234204845,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNDIwNDg0NQ==","diff_hunk":"@@ -790,6 +790,8 @@ def store_result(cls, org, data_source, query_hash, query, data, run_time, retri\n             Query.data_source == data_source)\n         for q in queries:\n             q.latest_query_data = query_result\n+            # ugly hack to avoid Query's updated_at from changing in this specific scenario\n+            q.updated_at = q.updated_at + datetime.timedelta(milliseconds=1)","path":"redash/models.py","position":5,"original_position":5,"commit_id":"1252ef7b8079c3f2363b0a6cf60429d7791f8002","original_commit_id":"1252ef7b8079c3f2363b0a6cf60429d7791f8002","user":{"login":"jezdez","id":1610,"node_id":"MDQ6VXNlcjE2MTA=","avatar_url":"https://avatars0.githubusercontent.com/u/1610?v=4","gravatar_id":"","url":"https://api.github.com/users/jezdez","html_url":"https://github.com/jezdez","followers_url":"https://api.github.com/users/jezdez/followers","following_url":"https://api.github.com/users/jezdez/following{/other_user}","gists_url":"https://api.github.com/users/jezdez/gists{/gist_id}","starred_url":"https://api.github.com/users/jezdez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jezdez/subscriptions","organizations_url":"https://api.github.com/users/jezdez/orgs","repos_url":"https://api.github.com/users/jezdez/repos","events_url":"https://api.github.com/users/jezdez/events{/privacy}","received_events_url":"https://api.github.com/users/jezdez/received_events","type":"User","site_admin":false},"body":"Let's not do that and instead fix the `TimestampMixin` class to optionally support not updating the `updated_at` value.\r\n\r\nTo do that we first have to change the mixin to stop using `onupdate` since it doesn't provide as with the hooks AFAIK to make educated guess, e.g. we don't have access to the ORM instance.\r\n\r\nInstead we can use the [`before_update` ORM event](https://docs.sqlalchemy.org/en/latest/orm/events.html#sqlalchemy.orm.events.MapperEvents.before_update) to conditionally update the `updated_at` column:\r\n\r\n```python\r\nfrom sqlalchemy.event import listens_for\r\n\r\nclass TimestampMixin(object):\r\n    updated_at = Column(db.DateTime(True), default=utcnow, nullable=False)\r\n    created_at = Column(db.DateTime(True), default=utcnow, nullable=False)\r\n\r\n@listens_for(TimestampMixin, 'before_update', propagate=True)\r\ndef timestamp_before_update(mapper, connection, target):\r\n    # Check if we really want to update the updated_at value\r\n    if hasattr(target.skip_updated_at):\r\n        return\r\n    target.updated_at = utcnow()\r\n```\r\n\r\nThen inside the `store_result` loop you can simply do:\r\n\r\n```python\r\nq.skip_updated_at = True\r\n```","created_at":"2018-11-16T13:36:45Z","updated_at":"2018-11-16T13:40:51Z","html_url":"https://github.com/getredash/redash/pull/3082#discussion_r234204845","pull_request_url":"https://api.github.com/repos/getredash/redash/pulls/3082","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/getredash/redash/pulls/comments/234204845"},"html":{"href":"https://github.com/getredash/redash/pull/3082#discussion_r234204845"},"pull_request":{"href":"https://api.github.com/repos/getredash/redash/pulls/3082"}}},"pull_request":{"url":"https://api.github.com/repos/getredash/redash/pulls/3082","id":230980624,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwOTgwNjI0","html_url":"https://github.com/getredash/redash/pull/3082","diff_url":"https://github.com/getredash/redash/pull/3082.diff","patch_url":"https://github.com/getredash/redash/pull/3082.patch","issue_url":"https://api.github.com/repos/getredash/redash/issues/3082","number":3082,"state":"open","locked":false,"title":"Prevent Query's updated_at from changing when it is linked to new query results","user":{"login":"rauchy","id":289488,"node_id":"MDQ6VXNlcjI4OTQ4OA==","avatar_url":"https://avatars2.githubusercontent.com/u/289488?v=4","gravatar_id":"","url":"https://api.github.com/users/rauchy","html_url":"https://github.com/rauchy","followers_url":"https://api.github.com/users/rauchy/followers","following_url":"https://api.github.com/users/rauchy/following{/other_user}","gists_url":"https://api.github.com/users/rauchy/gists{/gist_id}","starred_url":"https://api.github.com/users/rauchy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rauchy/subscriptions","organizations_url":"https://api.github.com/users/rauchy/orgs","repos_url":"https://api.github.com/users/rauchy/repos","events_url":"https://api.github.com/users/rauchy/events{/privacy}","received_events_url":"https://api.github.com/users/rauchy/received_events","type":"User","site_admin":false},"body":"Solves #2978, but in a way that makes chewing street chalk feel pleasant.\r\n\r\nBasically, the updated_at column was important to keep for all changes _other than_ the change of associated query data, and the only way I could find to override `TimestampMixin`'s onupdate logic was to assign a new value in that same transaction. This is the closest value I could find 🤦‍♂️\r\n\r\nPlease let me know if you can find a better solution.","created_at":"2018-11-14T21:03:15Z","updated_at":"2018-11-16T13:40:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c8cddbb78d300b33709a1c10d38c97fa7ed3c808","assignee":null,"assignees":[],"requested_reviewers":[{"login":"washort","id":947487,"node_id":"MDQ6VXNlcjk0NzQ4Nw==","avatar_url":"https://avatars2.githubusercontent.com/u/947487?v=4","gravatar_id":"","url":"https://api.github.com/users/washort","html_url":"https://github.com/washort","followers_url":"https://api.github.com/users/washort/followers","following_url":"https://api.github.com/users/washort/following{/other_user}","gists_url":"https://api.github.com/users/washort/gists{/gist_id}","starred_url":"https://api.github.com/users/washort/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washort/subscriptions","organizations_url":"https://api.github.com/users/washort/orgs","repos_url":"https://api.github.com/users/washort/repos","events_url":"https://api.github.com/users/washort/events{/privacy}","received_events_url":"https://api.github.com/users/washort/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/getredash/redash/pulls/3082/commits","review_comments_url":"https://api.github.com/repos/getredash/redash/pulls/3082/comments","review_comment_url":"https://api.github.com/repos/getredash/redash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getredash/redash/issues/3082/comments","statuses_url":"https://api.github.com/repos/getredash/redash/statuses/1252ef7b8079c3f2363b0a6cf60429d7791f8002","head":{"label":"getredash:prevent-updated-at-from-changing","ref":"prevent-updated-at-from-changing","sha":"1252ef7b8079c3f2363b0a6cf60429d7791f8002","user":{"login":"getredash","id":10746780,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNzQ2Nzgw","avatar_url":"https://avatars2.githubusercontent.com/u/10746780?v=4","gravatar_id":"","url":"https://api.github.com/users/getredash","html_url":"https://github.com/getredash","followers_url":"https://api.github.com/users/getredash/followers","following_url":"https://api.github.com/users/getredash/following{/other_user}","gists_url":"https://api.github.com/users/getredash/gists{/gist_id}","starred_url":"https://api.github.com/users/getredash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getredash/subscriptions","organizations_url":"https://api.github.com/users/getredash/orgs","repos_url":"https://api.github.com/users/getredash/repos","events_url":"https://api.github.com/users/getredash/events{/privacy}","received_events_url":"https://api.github.com/users/getredash/received_events","type":"Organization","site_admin":false},"repo":{"id":13926404,"node_id":"MDEwOlJlcG9zaXRvcnkxMzkyNjQwNA==","name":"redash","full_name":"getredash/redash","private":false,"owner":{"login":"getredash","id":10746780,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNzQ2Nzgw","avatar_url":"https://avatars2.githubusercontent.com/u/10746780?v=4","gravatar_id":"","url":"https://api.github.com/users/getredash","html_url":"https://github.com/getredash","followers_url":"https://api.github.com/users/getredash/followers","following_url":"https://api.github.com/users/getredash/following{/other_user}","gists_url":"https://api.github.com/users/getredash/gists{/gist_id}","starred_url":"https://api.github.com/users/getredash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getredash/subscriptions","organizations_url":"https://api.github.com/users/getredash/orgs","repos_url":"https://api.github.com/users/getredash/repos","events_url":"https://api.github.com/users/getredash/events{/privacy}","received_events_url":"https://api.github.com/users/getredash/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/getredash/redash","description":"Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.","fork":false,"url":"https://api.github.com/repos/getredash/redash","forks_url":"https://api.github.com/repos/getredash/redash/forks","keys_url":"https://api.github.com/repos/getredash/redash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getredash/redash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getredash/redash/teams","hooks_url":"https://api.github.com/repos/getredash/redash/hooks","issue_events_url":"https://api.github.com/repos/getredash/redash/issues/events{/number}","events_url":"https://api.github.com/repos/getredash/redash/events","assignees_url":"https://api.github.com/repos/getredash/redash/assignees{/user}","branches_url":"https://api.github.com/repos/getredash/redash/branches{/branch}","tags_url":"https://api.github.com/repos/getredash/redash/tags","blobs_url":"https://api.github.com/repos/getredash/redash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getredash/redash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getredash/redash/git/refs{/sha}","trees_url":"https://api.github.com/repos/getredash/redash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getredash/redash/statuses/{sha}","languages_url":"https://api.github.com/repos/getredash/redash/languages","stargazers_url":"https://api.github.com/repos/getredash/redash/stargazers","contributors_url":"https://api.github.com/repos/getredash/redash/contributors","subscribers_url":"https://api.github.com/repos/getredash/redash/subscribers","subscription_url":"https://api.github.com/repos/getredash/redash/subscription","commits_url":"https://api.github.com/repos/getredash/redash/commits{/sha}","git_commits_url":"https://api.github.com/repos/getredash/redash/git/commits{/sha}","comments_url":"https://api.github.com/repos/getredash/redash/comments{/number}","issue_comment_url":"https://api.github.com/repos/getredash/redash/issues/comments{/number}","contents_url":"https://api.github.com/repos/getredash/redash/contents/{+path}","compare_url":"https://api.github.com/repos/getredash/redash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getredash/redash/merges","archive_url":"https://api.github.com/repos/getredash/redash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getredash/redash/downloads","issues_url":"https://api.github.com/repos/getredash/redash/issues{/number}","pulls_url":"https://api.github.com/repos/getredash/redash/pulls{/number}","milestones_url":"https://api.github.com/repos/getredash/redash/milestones{/number}","notifications_url":"https://api.github.com/repos/getredash/redash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getredash/redash/labels{/name}","releases_url":"https://api.github.com/repos/getredash/redash/releases{/id}","deployments_url":"https://api.github.com/repos/getredash/redash/deployments","created_at":"2013-10-28T13:19:39Z","updated_at":"2018-11-16T04:48:48Z","pushed_at":"2018-11-15T20:11:44Z","git_url":"git://github.com/getredash/redash.git","ssh_url":"git@github.com:getredash/redash.git","clone_url":"https://github.com/getredash/redash.git","svn_url":"https://github.com/getredash/redash","homepage":"http://redash.io/","size":12369,"stargazers_count":10767,"watchers_count":10767,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1714,"mirror_url":null,"archived":false,"open_issues_count":441,"license":{"key":"bsd-2-clause","name":"BSD 2-Clause \"Simplified\" License","spdx_id":"BSD-2-Clause","url":"https://api.github.com/licenses/bsd-2-clause","node_id":"MDc6TGljZW5zZTQ="},"forks":1714,"open_issues":441,"watchers":10767,"default_branch":"master"}},"base":{"label":"getredash:master","ref":"master","sha":"8bb96c8c9170b016473745f41466cf706405588e","user":{"login":"getredash","id":10746780,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNzQ2Nzgw","avatar_url":"https://avatars2.githubusercontent.com/u/10746780?v=4","gravatar_id":"","url":"https://api.github.com/users/getredash","html_url":"https://github.com/getredash","followers_url":"https://api.github.com/users/getredash/followers","following_url":"https://api.github.com/users/getredash/following{/other_user}","gists_url":"https://api.github.com/users/getredash/gists{/gist_id}","starred_url":"https://api.github.com/users/getredash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getredash/subscriptions","organizations_url":"https://api.github.com/users/getredash/orgs","repos_url":"https://api.github.com/users/getredash/repos","events_url":"https://api.github.com/users/getredash/events{/privacy}","received_events_url":"https://api.github.com/users/getredash/received_events","type":"Organization","site_admin":false},"repo":{"id":13926404,"node_id":"MDEwOlJlcG9zaXRvcnkxMzkyNjQwNA==","name":"redash","full_name":"getredash/redash","private":false,"owner":{"login":"getredash","id":10746780,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwNzQ2Nzgw","avatar_url":"https://avatars2.githubusercontent.com/u/10746780?v=4","gravatar_id":"","url":"https://api.github.com/users/getredash","html_url":"https://github.com/getredash","followers_url":"https://api.github.com/users/getredash/followers","following_url":"https://api.github.com/users/getredash/following{/other_user}","gists_url":"https://api.github.com/users/getredash/gists{/gist_id}","starred_url":"https://api.github.com/users/getredash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getredash/subscriptions","organizations_url":"https://api.github.com/users/getredash/orgs","repos_url":"https://api.github.com/users/getredash/repos","events_url":"https://api.github.com/users/getredash/events{/privacy}","received_events_url":"https://api.github.com/users/getredash/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/getredash/redash","description":"Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.","fork":false,"url":"https://api.github.com/repos/getredash/redash","forks_url":"https://api.github.com/repos/getredash/redash/forks","keys_url":"https://api.github.com/repos/getredash/redash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getredash/redash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getredash/redash/teams","hooks_url":"https://api.github.com/repos/getredash/redash/hooks","issue_events_url":"https://api.github.com/repos/getredash/redash/issues/events{/number}","events_url":"https://api.github.com/repos/getredash/redash/events","assignees_url":"https://api.github.com/repos/getredash/redash/assignees{/user}","branches_url":"https://api.github.com/repos/getredash/redash/branches{/branch}","tags_url":"https://api.github.com/repos/getredash/redash/tags","blobs_url":"https://api.github.com/repos/getredash/redash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getredash/redash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getredash/redash/git/refs{/sha}","trees_url":"https://api.github.com/repos/getredash/redash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getredash/redash/statuses/{sha}","languages_url":"https://api.github.com/repos/getredash/redash/languages","stargazers_url":"https://api.github.com/repos/getredash/redash/stargazers","contributors_url":"https://api.github.com/repos/getredash/redash/contributors","subscribers_url":"https://api.github.com/repos/getredash/redash/subscribers","subscription_url":"https://api.github.com/repos/getredash/redash/subscription","commits_url":"https://api.github.com/repos/getredash/redash/commits{/sha}","git_commits_url":"https://api.github.com/repos/getredash/redash/git/commits{/sha}","comments_url":"https://api.github.com/repos/getredash/redash/comments{/number}","issue_comment_url":"https://api.github.com/repos/getredash/redash/issues/comments{/number}","contents_url":"https://api.github.com/repos/getredash/redash/contents/{+path}","compare_url":"https://api.github.com/repos/getredash/redash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getredash/redash/merges","archive_url":"https://api.github.com/repos/getredash/redash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getredash/redash/downloads","issues_url":"https://api.github.com/repos/getredash/redash/issues{/number}","pulls_url":"https://api.github.com/repos/getredash/redash/pulls{/number}","milestones_url":"https://api.github.com/repos/getredash/redash/milestones{/number}","notifications_url":"https://api.github.com/repos/getredash/redash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getredash/redash/labels{/name}","releases_url":"https://api.github.com/repos/getredash/redash/releases{/id}","deployments_url":"https://api.github.com/repos/getredash/redash/deployments","created_at":"2013-10-28T13:19:39Z","updated_at":"2018-11-16T04:48:48Z","pushed_at":"2018-11-15T20:11:44Z","git_url":"git://github.com/getredash/redash.git","ssh_url":"git@github.com:getredash/redash.git","clone_url":"https://github.com/getredash/redash.git","svn_url":"https://github.com/getredash/redash","homepage":"http://redash.io/","size":12369,"stargazers_count":10767,"watchers_count":10767,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1714,"mirror_url":null,"archived":false,"open_issues_count":441,"license":{"key":"bsd-2-clause","name":"BSD 2-Clause \"Simplified\" License","spdx_id":"BSD-2-Clause","url":"https://api.github.com/licenses/bsd-2-clause","node_id":"MDc6TGljZW5zZTQ="},"forks":1714,"open_issues":441,"watchers":10767,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getredash/redash/pulls/3082"},"html":{"href":"https://github.com/getredash/redash/pull/3082"},"issue":{"href":"https://api.github.com/repos/getredash/redash/issues/3082"},"comments":{"href":"https://api.github.com/repos/getredash/redash/issues/3082/comments"},"review_comments":{"href":"https://api.github.com/repos/getredash/redash/pulls/3082/comments"},"review_comment":{"href":"https://api.github.com/repos/getredash/redash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getredash/redash/pulls/3082/commits"},"statuses":{"href":"https://api.github.com/repos/getredash/redash/statuses/1252ef7b8079c3f2363b0a6cf60429d7791f8002"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jezdez"}}