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

query_runner -> query_results: improve logging, handle unhandled data types #6905

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

vtatarin
Copy link

@vtatarin vtatarin commented Apr 18, 2024

What type of PR is this?

  • Refactor
  • Feature
  • Bug Fix
  • New Query Runner (Data Source)
  • New Alert Destination
  • Other

Description

[2024-04-17 23:26:24,952][PID:227][DEBUG][redash.query_runner.query_results] CREATE TABLE query: CREATE TABLE query_10000 ("a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n", "b", "v", "c", "x", "z", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "q", "w", "e", "r", "t", "y", "u")
[2024-04-17 23:26:24,953][PID:227][WARNING][rq.job.redash.tasks.queries.execution] job.func_name=redash.tasks.queries.execution.execute_query job.id=0ae029e6-27ef-4482-93fc-1e7498cf08f7 Unexpected error while running query:
Traceback (most recent call last):
  File "/app/redash/tasks/queries/execution.py", line 182, in run
    data, error = query_runner.run_query(annotated_query, self.user)
  File "/app/redash/query_runner/query_results.py", line 172, in run_query
    create_tables_from_query_ids(user, connection, query_ids, query_params, cached_query_ids)
  File "/app/redash/query_runner/query_results.py", line 100, in create_tables_from_query_ids
    create_table(connection, table_name, results)
  File "/app/redash/query_runner/query_results.py", line 140, in create_table
    connection.execute(insert_template, values)
sqlite3.InterfaceError: Error binding parameter 6 - probably unsupported type.

Values:

[2024-04-18 03:40:40,086][PID:118][DEBUG][redash.query_runner.query_results] Value: 18227135, Type: <class 'int'>
[2024-04-18 03:40:40,086][PID:118][DEBUG][redash.query_runner.query_results] Value: redacted, Type: <class 'str'>
[2024-04-18 03:40:40,086][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-07, Type: <class 'datetime.date'>
[2024-04-18 03:40:40,086][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-07, Type: <class 'datetime.date'>
[2024-04-18 03:40:40,086][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-06, Type: <class 'datetime.date'>
[2024-04-18 03:40:40,086][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-01, Type: <class 'datetime.date'>
[2024-04-18 03:40:40,087][PID:118][DEBUG][redash.query_runner.query_results] Value: 12:52:54, Type: <class 'datetime.time'>
[2024-04-18 03:40:40,087][PID:118][DEBUG][redash.query_runner.query_results] Value: 12:57:38, Type: <class 'datetime.time'>
[2024-04-18 03:40:40,087][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-07 12:52:54+00:00, Type: <class 'datetime.datetime'>
[2024-04-18 03:40:40,087][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-07 12:57:38+00:00, Type: <class 'datetime.datetime'>
[2024-04-18 03:40:40,087][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-07 20:52:54+00:00, Type: <class 'datetime.datetime'>
[2024-04-18 03:40:40,087][PID:118][DEBUG][redash.query_runner.query_results] Value: 2023-03-07 20:57:38+00:00, Type: <class 'datetime.datetime'>
[2024-04-18 03:40:40,087][PID:118][DEBUG][redash.query_runner.query_results] Value: redacted, Type: <class 'str'>

How is this tested?

  • Unit tests (pytest, jest)
  • E2E Tests (Cypress)
  • Manually
  • N/A

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

@justinclift
Copy link
Member

What type of data source is it trying to use when this happens, and which version of Redash is it happening on? 😄

@AndrewChubatiuk
Copy link
Collaborator

@justinclift this is a version from master

@justinclift
Copy link
Member

@AndrewChubatiuk Ahhh. Do you want to take a look at it then? You've probably been doing stuff with that part of things recently, whereas I haven't (yet). 😄

@vtatarin
Copy link
Author

@justinclift that's from QueryResults data source

@vtatarin
Copy link
Author

Hello @justinclift @AndrewChubatiuk
I've tested my changes in our installation Redash running from the latest master branch- it fixes the issue.

Please review this change. Thank you!

@vtatarin vtatarin changed the title [WIP] Fix query_runner Fix query_runner Apr 19, 2024
@AndrewChubatiuk
Copy link
Collaborator

AndrewChubatiuk commented Apr 20, 2024

LGTM
please just update PR name and fix tests

Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 63.77%. Comparing base (372adfe) to head (5e69e3f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6905   +/-   ##
=======================================
  Coverage   63.76%   63.77%           
=======================================
  Files         161      161           
  Lines       13085    13089    +4     
  Branches     1812     1814    +2     
=======================================
+ Hits         8344     8347    +3     
  Misses       4438     4438           
- Partials      303      304    +1     
Files Coverage Δ
redash/query_runner/query_results.py 63.57% <80.00%> (+0.33%) ⬆️

@vtatarin vtatarin changed the title Fix query_runner query_runner -> query_results: improve logging, handle unhandled data types Apr 30, 2024
@vtatarin
Copy link
Author

hey @justinclift @AndrewChubatiuk
please review and merge this PR, all checks should be green now. It's an important fix for my team

@@ -134,6 +137,7 @@ def create_table(connection, table_name, query_results):
column_list=column_list,
place_holders=",".join(["?"] * len(columns)),
)
logger.debug("INSERT template: %s", insert_template)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we don't want debugging statements being unconditionally run. At least with the change above it, it seems to be done conditionally there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinclift thank you for the reply! So there are 2 things:

  • logger only logs (prints to stdout/stderr) messages, nothing is actually run/executed. The default log level is INFO, so logger.debug is actually a condition which logs the data only at a more verbose level
  • for another added logger there is a condition that checks the current log level and prevents going through too many checks unless its DEBUG (which is not default)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vtatarin Sorry, but I'm short on time for the next few weeks.

Am getting some (Redash related) stuff deployed to a data centre, and that's taking the majority of my focus time. When that's done I'll be able to look at PRs properly. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants