Skip to content

Commit

Permalink
Remove deprecated advocate package (#6944)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewChubatiuk authored May 6, 2024
1 parent bd17662 commit bd115e7
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 137 deletions.
77 changes: 1 addition & 76 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.8,<3.11"
advocate = "1.0.0"
aniso8601 = "8.0.0"
authlib = "0.15.5"
backoff = "2.2.1"
Expand Down
15 changes: 4 additions & 11 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
from contextlib import ExitStack
from functools import wraps

import requests
import sqlparse
from dateutil import parser
from rq.timeouts import JobTimeoutException
from sshtunnel import open_tunnel

from redash import settings, utils
from redash.utils.requests_session import (
UnacceptableAddressException,
requests_or_advocate,
requests_session,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -379,7 +375,7 @@ def get_response(self, url, auth=None, http_method="get", **kwargs):
error = None
response = None
try:
response = requests_session.request(http_method, url, auth=auth, **kwargs)
response = requests.request(http_method, url, auth=auth, **kwargs)
# Raise a requests HTTP exception with the appropriate reason
# for 4xx and 5xx response status codes which is later caught
# and passed back.
Expand All @@ -389,14 +385,11 @@ def get_response(self, url, auth=None, http_method="get", **kwargs):
if response.status_code != 200:
error = "{} ({}).".format(self.response_error, response.status_code)

except requests_or_advocate.HTTPError as exc:
except requests.HTTPError as exc:
logger.exception(exc)
error = "Failed to execute query. "
f"Return Code: {response.status_code} Reason: {response.text}"
except UnacceptableAddressException as exc:
logger.exception(exc)
error = "Can't query private addresses."
except requests_or_advocate.RequestException as exc:
except requests.RequestException as exc:
# Catch all other requests exceptions and return the error.
logger.exception(exc)
error = str(exc)
Expand Down
10 changes: 2 additions & 8 deletions redash/query_runner/csv.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import io
import logging

import requests
import yaml

from redash.query_runner import BaseQueryRunner, NotSupported, register
from redash.utils.requests_session import (
UnacceptableAddressException,
requests_or_advocate,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -59,7 +56,7 @@ def run_query(self, query, user):
pass

try:
response = requests_or_advocate.get(url=path, headers={"User-agent": ua})
response = requests.get(url=path, headers={"User-agent": ua})
workbook = pd.read_csv(io.BytesIO(response.content), sep=",", **args)

df = workbook.copy()
Expand Down Expand Up @@ -99,9 +96,6 @@ def run_query(self, query, user):
except KeyboardInterrupt:
error = "Query cancelled by user."
data = None
except UnacceptableAddressException:
error = "Can't query private addresses."
data = None
except Exception as e:
error = "Error reading {0}. {1}".format(path, str(e))
data = None
Expand Down
10 changes: 2 additions & 8 deletions redash/query_runner/excel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import logging

import requests
import yaml

from redash.query_runner import BaseQueryRunner, NotSupported, register
from redash.utils.requests_session import (
UnacceptableAddressException,
requests_or_advocate,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -57,7 +54,7 @@ def run_query(self, query, user):
pass

try:
response = requests_or_advocate.get(url=path, headers={"User-agent": ua})
response = requests.get(url=path, headers={"User-agent": ua})
workbook = pd.read_excel(response.content, **args)

df = workbook.copy()
Expand Down Expand Up @@ -97,9 +94,6 @@ def run_query(self, query, user):
except KeyboardInterrupt:
error = "Query cancelled by user."
data = None
except UnacceptableAddressException:
error = "Can't query private addresses."
data = None
except Exception as e:
error = "Error reading {0}. {1}".format(path, str(e))
data = None
Expand Down
3 changes: 0 additions & 3 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
# Whether file downloads are enforced or not.
ENFORCE_FILE_SAVE = parse_boolean(os.environ.get("REDASH_ENFORCE_FILE_SAVE", "true"))

# Whether api calls using the json query runner will block private addresses
ENFORCE_PRIVATE_ADDRESS_BLOCK = parse_boolean(os.environ.get("REDASH_ENFORCE_PRIVATE_IP_BLOCK", "true"))

# Whether to use secure cookies by default.
COOKIES_SECURE = parse_boolean(os.environ.get("REDASH_COOKIES_SECURE", str(ENFORCE_HTTPS)))
# Whether the session cookie is set to secure.
Expand Down
18 changes: 0 additions & 18 deletions redash/utils/requests_session.py

This file was deleted.

21 changes: 9 additions & 12 deletions tests/query_runner/test_http.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from unittest import TestCase

import mock
import requests

from redash.query_runner import BaseHTTPQueryRunner
from redash.utils.requests_session import (
ConfiguredSession,
requests_or_advocate,
)


class RequiresAuthQueryRunner(BaseHTTPQueryRunner):
Expand Down Expand Up @@ -37,7 +34,7 @@ def test_get_auth_empty_requires_authentication(self):
query_runner = RequiresAuthQueryRunner({})
self.assertRaisesRegex(ValueError, "Username and Password required", query_runner.get_auth)

@mock.patch.object(ConfiguredSession, "request")
@mock.patch("requests.request")
def test_get_response_success(self, mock_get):
mock_response = mock.Mock()
mock_response.status_code = 200
Expand All @@ -51,7 +48,7 @@ def test_get_response_success(self, mock_get):
self.assertEqual(response.status_code, 200)
self.assertIsNone(error)

@mock.patch.object(ConfiguredSession, "request")
@mock.patch("requests.request")
def test_get_response_success_custom_auth(self, mock_get):
mock_response = mock.Mock()
mock_response.status_code = 200
Expand All @@ -66,7 +63,7 @@ def test_get_response_success_custom_auth(self, mock_get):
self.assertEqual(response.status_code, 200)
self.assertIsNone(error)

@mock.patch.object(ConfiguredSession, "request")
@mock.patch("requests.request")
def test_get_response_failure(self, mock_get):
mock_response = mock.Mock()
mock_response.status_code = 301
Expand All @@ -79,12 +76,12 @@ def test_get_response_failure(self, mock_get):
mock_get.assert_called_once_with("get", url, auth=None)
self.assertIn(query_runner.response_error, error)

@mock.patch.object(ConfiguredSession, "request")
@mock.patch("requests.request")
def test_get_response_httperror_exception(self, mock_get):
mock_response = mock.Mock()
mock_response.status_code = 500
mock_response.text = "Server Error"
http_error = requests_or_advocate.HTTPError()
http_error = requests.HTTPError()
mock_response.raise_for_status.side_effect = http_error
mock_get.return_value = mock_response

Expand All @@ -95,13 +92,13 @@ def test_get_response_httperror_exception(self, mock_get):
self.assertIsNotNone(error)
self.assertIn("Failed to execute query", error)

@mock.patch.object(ConfiguredSession, "request")
@mock.patch("requests.request")
def test_get_response_requests_exception(self, mock_get):
mock_response = mock.Mock()
mock_response.status_code = 500
mock_response.text = "Server Error"
exception_message = "Some requests exception"
requests_exception = requests_or_advocate.RequestException(exception_message)
requests_exception = requests.RequestException(exception_message)
mock_response.raise_for_status.side_effect = requests_exception
mock_get.return_value = mock_response

Expand All @@ -112,7 +109,7 @@ def test_get_response_requests_exception(self, mock_get):
self.assertIsNotNone(error)
self.assertEqual(exception_message, error)

@mock.patch.object(ConfiguredSession, "request")
@mock.patch("requests.request")
def test_get_response_generic_exception(self, mock_get):
mock_response = mock.Mock()
mock_response.status_code = 500
Expand Down

0 comments on commit bd115e7

Please sign in to comment.