mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Fix 'str' object has no attribute 'pop' error when parsing query (#6941)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import logging
|
||||
from typing import Optional, Tuple
|
||||
|
||||
@@ -64,6 +65,7 @@ class ElasticSearch2(BaseHTTPQueryRunner):
|
||||
return data, error
|
||||
|
||||
def _build_query(self, query: str) -> Tuple[dict, str, Optional[list]]:
|
||||
query = json.loads(query)
|
||||
index_name = query.pop("index", "")
|
||||
result_fields = query.pop("result_fields", None)
|
||||
url = "/{}/_search".format(index_name)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from unittest import TestCase
|
||||
from unittest import TestCase, mock
|
||||
|
||||
from redash.query_runner.elasticsearch2 import (
|
||||
ElasticSearch2,
|
||||
@@ -137,3 +137,14 @@ class TestXPackSQL(TestCase):
|
||||
],
|
||||
}
|
||||
self.assertDictEqual(XPackSQLElasticSearch._parse_results(None, response), expected)
|
||||
|
||||
|
||||
class TestElasticSearch2(TestCase):
|
||||
@mock.patch("redash.query_runner.elasticsearch2.ElasticSearch2.__init__", return_value=None)
|
||||
def test_build_query(self, mock_init):
|
||||
query_runner = ElasticSearch2()
|
||||
query_str = '{"index": "test_index", "result_fields": ["field1", "field2"]}'
|
||||
query_dict, url, result_fields = query_runner._build_query(query_str)
|
||||
self.assertEqual(query_dict, {})
|
||||
self.assertEqual(url, "/test_index/_search")
|
||||
self.assertEqual(result_fields, ["field1", "field2"])
|
||||
|
||||
Reference in New Issue
Block a user