From 650b07d7b07a779069ee81faf0de6e1dee754c85 Mon Sep 17 00:00:00 2001 From: Kennedy Kori Date: Tue, 20 Sep 2022 16:38:44 +0300 Subject: [PATCH] fix(http): extract metadata fetching Fix bug causing duplication of extract metadata when working with multiple data sources and while using HTTP Transport. --- app/lib/transports/http/api_v1_dialect.py | 1 + app/lib/transports/http/http_transport.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/lib/transports/http/api_v1_dialect.py b/app/lib/transports/http/api_v1_dialect.py index 7353852..be9198d 100644 --- a/app/lib/transports/http/api_v1_dialect.py +++ b/app/lib/transports/http/api_v1_dialect.py @@ -121,6 +121,7 @@ def fetch_data_source_extracts( ) -> HTTPRequestParams: return { "headers": {"Accept": "application/json"}, + "params": {"data_source": data_source.id}, "expected_http_status_code": 200, "method": _GET_METHOD, "url": "%s/%s/sql_extract_metadata/" diff --git a/app/lib/transports/http/http_transport.py b/app/lib/transports/http/http_transport.py index 98c0a12..5927f7f 100644 --- a/app/lib/transports/http/http_transport.py +++ b/app/lib/transports/http/http_transport.py @@ -28,6 +28,21 @@ _LOGGER = logging.getLogger(__name__) +# ============================================================================= +# HELPER TASKS +# ============================================================================= + + +def _log_response( + response: Response, *args, **kwargs +) -> None: # pragma: no cover + request_message: str = "HTTP Request ({} | {})".format( + response.request.method, + response.request.url, + ) + _LOGGER.debug(request_message) + + # ============================================================================= # HTTP TRANSPORT # ============================================================================= @@ -71,6 +86,7 @@ def __init__( "User-Agent": f"{__title__}/{__version__}", } ) + self._session.hooks["response"].append(_log_response) self._auth: AuthBase = _NoAuth() self._is_closed: bool = False @@ -190,7 +206,7 @@ def post_upload_metadata( # ------------------------------------------------------------------------- def _authenticate(self) -> AuthBase: self._ensure_not_closed() - _LOGGER.info("Authenticating HTTP transport.") + _LOGGER.debug("Authenticating HTTP transport.") request: HTTPRequestParams = self._api_dialect.authenticate() response: Response = self._session.request( data=request.get("data"), @@ -226,7 +242,6 @@ def _make_request(self, request: HTTPRequestParams) -> Response: request["method"], request["url"], ) - _LOGGER.info(request_message) response: Response = self._session.request( data=request.get("data"), files=request.get("files"),