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

Fix Elasticsearch query runner error: 'str' object has no attribute 'pop' error when parsing query #6941

Merged
merged 1 commit into from
May 2, 2024

Conversation

jcowley
Copy link
Contributor

@jcowley jcowley commented May 2, 2024

What type of PR is this?

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

Description

Fix Elasticsearch query runner (refactored version not yet released)

How is this tested?

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

I needed redash to work with elasticsearch 7.10, but the current v10.1.0 release does not support it. There was a major refactor of the elasticsearch query runner in #5794, but that code has not yet been released. So, I got the latest from master and tried it out.

I'm not sure how this code was tested originally, but it doesn't work because of a very minor bug. When building the elasticsearch query, it's trying to call pop() on the query parameter which is of type str, and there is no pop() method on str. Any attempt to run an elasticsearch query results in the error:

'str' object has no attribute 'pop' error when parsing query

It needs to be converted to a dictionary, which is a one line change. Then it works fine.

Not sure how this wasn't caught earlier. Maybe no one has tried it out yet? I do appreciate all the hard work that @NicolasLM, @susodapop, and @wwl717195673 put into the refactor. It's been working well for us after this fix.

Related Tickets & Documents

#5794

@jcowley jcowley force-pushed the fix-elasticsearch branch from 1ae0adb to 7470528 Compare May 2, 2024 05:27
Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.80%. Comparing base (897c683) to head (6769dbd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6941      +/-   ##
==========================================
+ Coverage   63.76%   63.80%   +0.03%     
==========================================
  Files         161      161              
  Lines       13085    13087       +2     
  Branches     1812     1812              
==========================================
+ Hits         8344     8350       +6     
+ Misses       4438     4434       -4     
  Partials      303      303              
Files Coverage Δ
redash/query_runner/elasticsearch2.py 62.75% <100.00%> (+2.44%) ⬆️

@jcowley jcowley force-pushed the fix-elasticsearch branch 3 times, most recently from 23ac140 to 667699c Compare May 2, 2024 06:28
@jcowley jcowley force-pushed the fix-elasticsearch branch from 667699c to 6769dbd Compare May 2, 2024 06:44
@justinclift
Copy link
Member

Hmmm, wonder if this was caused by the pseudojson change back in Jan? ec1c4d0

That being said, this bug definitely needs fixing. 😄

@AndrewChubatiuk Are you ok to review this?

Copy link
Contributor

@AndrewChubatiuk AndrewChubatiuk left a comment

Choose a reason for hiding this comment

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

LGTM

@justinclift
Copy link
Member

Thanks @AndrewChubatiuk. 😄

Copy link
Member

@justinclift justinclift left a comment

Choose a reason for hiding this comment

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

Looks straight forward enough, and @AndrewChubatiuk didn't spot anything wrong. 😄

@justinclift justinclift merged commit b7f22b1 into getredash:master May 2, 2024
13 checks passed
@justinclift
Copy link
Member

@jcowley Thanks for spotting this, and fixing it. 😄

@jcowley
Copy link
Contributor Author

jcowley commented May 2, 2024

No problem. Thanks for getting it merged in.

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.

3 participants