-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
[sqllab] fix exception caused by casting string to int with psycopg2 #9287
Conversation
I haven't been following the specifics of the SQL Lab backend persistence work, so I might have missed something crucial. What I don't understand is why are we sometimes casting something that's a string/hash into an integer? |
@villebro the migration of the SQL Lab state from We could've used strings for IDs in the backend as well, but since I was expecting the lifetime of the feature flag to be small and that people would adopt it quickly, I opted for using ints and handling the corner cases. |
Codecov Report
@@ Coverage Diff @@
## master #9287 +/- ##
=======================================
Coverage 58.90% 58.90%
=======================================
Files 373 373
Lines 12026 12026
Branches 2953 2953
=======================================
Hits 7084 7084
Misses 4763 4763
Partials 179 179
Continue to review full report at Codecov.
|
@villebro part of the tabs migration process, which happens once the user visits sqllab when this feature is enabled, involves using the tab id(int) cast to a string as the |
@betodealmeida @nytai my concern with the current exception handling is that is looks like it simply fails the process if a string can't be cast to an int. How do we ensure that affected queries don't get lost in the process? Sorry if I'm missing something obvious. |
Yeah, @villebro is right. I think the problem here is that we might have leftover queries in the We should filter out these queries, returning only queries that have a |
user_queries = ( | ||
db.session.query(Query) | ||
.filter_by(user_id=user_id) | ||
.filter(Query.sql_editor_id.cast(Integer).in_(tab_state_ids)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nytai what if you do this:
tab_state_ids = [str(tab_state[0]) for tab_state in tabs_state]
...
user_queries = (
db.session.query(Query)
.filter_by(user_id=user_id)
.filter(Query.sql_editor_id.in_(tab_state_ids))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, that definitely works! Earlier I was trying to figure out how to craft some regex to filter out rows where sql_editor_id is not numeric... casting the ids to strings makes more sense 😄
@villebro good catch, we would have always been wiping user's queries with the exception handling approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome sauce!
CATEGORY
Choose one
SUMMARY
There's an issue with running the feature SQLLAB_BACKEND_PERSISTENCE whole using postgres as the metadata db.
For the expression
CAST('JUScSB3M_' as INTEGER)
MySQL and SQLite produce0
, postgres raises an exception:sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for integer: "JUScSB3M_"
.This causes an unhandled exception at this line: https://github.com/apache/incubator-superset/pull/8769/files#r384774308
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
error can be reproduced by:
With the changes in this PR the above exception no longer occurs.
ADDITIONAL INFORMATION
REVIEWERS
@betodealmeida @robdiciuccio @villebro @craig-rueda @robdiciuccio