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
When editing a data source template, inconsistent results can be seen due to database query #3350
Comments
Have you considered a pull request? Good catch by the way! |
Thanks for the response. I have not considered a pull request because all my attempts thus far to compose a working equivalent SQL query have failed. My SQL abilities may not be good enough to come up with a graceful solution to this problem on my own, so I was hoping for some help with that. Even if you try to add some ordering to the query it seems to break the SUM() portion of the query which tries to sum up the data sources using the template. I've also tried variations of the query using SUM(IF(dl.data_template_id = '41', 1, 0)) instead but I run into the same problem. I can't seem to make it work without reverting to two queries. |
I commissioned some SQL expertise from within my company here and we came up with this as a possible alternative:
|
I just made some comments. We need the fix against the 1.2.x branch. Otherwise, looks good and no negative performance impact. |
Some SQL queries can break if a database is exported then imported
Describe the bug
Some SQL queries can return inconsistent results depending on the order in which rows were added to the database and/or database version.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Templates which displayed complete information without errors prior to the upgrade and database dump/import will continue to appear in the GUI with complete information and without errors.
In the screenshot below the template is missing its name, data input method and has the wrong data source profile.
Screenshots

Desktop (please complete the following information):
Additional context
This problem appears to be caused by this SQL query (similar ones may have this issue as well):
Where this query should return the template information for template ID 41, it returns an empty set on the post-upgrade database, but the expected data on the pre-upgrade database:
The reason for this is that the query can only return one row due to the SUM(CASE WHEN dl.data_template_id = '41' THEN 1 ELSE 0 END) AS data_sources portion of the query. Without any type of forced ORDERING this will cause the query to return the first chronologically inserted row in the database which matches. Under normal circumstances this will always be the template and the query will work. However, if the database is changed in such a way where the rows could be inserted in a different chronological order - such as during an dump/import operation - this query can break and return nothing.
For example, in the pre-upgrade database the slightly-modified version of this query returns:
This is expected, and when the HAVING filter is applied to this result it will match and the row is returned.
In the post-upgrade/import database the same query returns a different row:
This is a data source - not a template. When the HAVING filter is applied this returns an empty set and the template is broken.
The text was updated successfully, but these errors were encountered: