032: dead code cleanup — remove sync APIClient, _llm_http, preview_llm_client, fix retry chains

This commit is contained in:
2026-06-05 08:31:18 +03:00
parent 58e994cd75
commit 5eb116509b
9 changed files with 20 additions and 460 deletions

View File

@@ -134,87 +134,4 @@ class SupersetAuthCache:
with cls._lock:
cls._entries.pop(key, None)
# #endregion SupersetAuthCache
# #region APIClient [C:3] [TYPE Class]
# @BRIEF Synchronous Superset API client with process-local auth token caching. [DEPRECATED — use AsyncAPIClient]
# @DEPRECATED 2026-06-04 — replaced by AsyncAPIClient in async_network.py
# @REPLACED_BY -> [AsyncAPIClient]
# @RELATION DEPENDS_ON -> [SupersetAuthCache]
# @RELATION DEPENDS_ON -> [LoggerModule]
class APIClient:
"""Synchronous Superset API client — DEPRECATED. Use AsyncAPIClient from async_network.py."""
DEFAULT_TIMEOUT = 30
def __init__(self, config, verify_ssl=True, timeout=DEFAULT_TIMEOUT):
self.base_url = self._normalize_base_url(config.get("base_url", ""))
self.api_base_url = f"{self.base_url}/api/v1"
self.auth = config.get("auth")
self.request_settings = {"verify_ssl": verify_ssl, "timeout": timeout}
self._init_session()
self._tokens = {}
self._authenticated = False
self._auth_cache_key = SupersetAuthCache.build_key(self.base_url, self.auth, verify_ssl)
def _normalize_base_url(self, raw_url): return raw_url.strip().rstrip("/").removesuffix("/api/v1").rstrip("/")
def _build_api_url(self, endpoint): return f"{self.api_base_url}/{endpoint.lstrip('/')}"
def _init_session(self):
import requests
from requests.adapters import HTTPAdapter
self.session = requests.Session()
adapter = HTTPAdapter(pool_connections=10, pool_maxsize=10, max_retries=3)
self.session.mount("https://", adapter)
self.session.mount("http://", adapter)
def authenticate(self):
"""DEPRECATED: use AsyncAPIClient.authenticate()"""
cached = SupersetAuthCache.get(self._auth_cache_key)
if cached and cached.get("access_token") and cached.get("csrf_token"):
self._tokens = cached; self._authenticated = True; return self._tokens
# Raises RuntimeError indicating sync path is deprecated
raise RuntimeError("APIClient.authenticate() is deprecated. Use AsyncAPIClient.authenticate()")
@property
def headers(self):
if not self._authenticated: self.authenticate()
return {"Authorization": f"Bearer {self._tokens['access_token']}",
"X-CSRFToken": self._tokens.get("csrf_token", ""),
"Referer": self.base_url, "Content-Type": "application/json"}
def request(self, method, endpoint, **kwargs):
raise RuntimeError("APIClient.request() is deprecated. Use AsyncAPIClient.request()")
def upload_file(self, endpoint, file_info, **kwargs):
raise RuntimeError("APIClient.upload_file() is deprecated. Use AsyncAPIClient.request()")
def fetch_paginated_count(self, endpoint, query_params=None, count_field="count"):
raise RuntimeError("APIClient.fetch_paginated_count() is deprecated. Use AsyncAPIClient.fetch_paginated_count()")
def fetch_paginated_data(self, endpoint, pagination_options=None):
raise RuntimeError("APIClient.fetch_paginated_data() is deprecated. Use AsyncAPIClient.fetch_paginated_data()")
# Stub methods kept for backward-compat tests
def _handle_http_error(self, exc, endpoint):
"""DEPRECATED — error translation preserved for backward-compat tests.
Translates HTTP errors: 404→DashboardNotFoundError/SupersetAPIError."""
from requests.exceptions import HTTPError
if isinstance(exc, HTTPError) and exc.response is not None:
status_code = exc.response.status_code
if status_code == 404:
if self._is_dashboard_endpoint(endpoint):
raise DashboardNotFoundError(endpoint) from exc
raise SupersetAPIError(
f"API resource not found at endpoint '{endpoint}'",
status_code=status_code, endpoint=endpoint, subtype="not_found",
) from exc
raise SupersetAPIError(f"API Error: {exc}", status_code=getattr(exc, 'response', None) and exc.response.status_code) from exc
def _is_dashboard_endpoint(self, endpoint):
if not endpoint:
return False
ne = str(endpoint).strip().lower()
return ne.startswith("/dashboard/") or ne == "/dashboard"
def _handle_network_error(self, exc, url):
raise RuntimeError("APIClient._handle_network_error() is deprecated. Use AsyncAPIClient.")
# #endregion APIClient
# #endregion NetworkModule