Skip to content

Commit eaa7619

Browse files
authored
fix: Use configured server_url for split page dummy request (#192)
Fixes #191. Due to a limitation in our templated codebase, we need our split page logic to return a request that's just going to give a 200 response. Then, we jump back into the AfterSuccessHook and await all of the pdf splits. Hopefully we can clean this up soon to avoid having an extra call at all, but for now let's make sure the GET /general/docs is done on the correct base url.
1 parent 18a1309 commit eaa7619

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

Diff for: CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.26.1
2+
3+
### Enhancements
4+
5+
### Features
6+
7+
### Fixes
8+
* Use the configured server_url for our split page "dummy" request
9+
110
## 0.26.0
211

312
### Enhancements

Diff for: _test_unstructured_client/integration/test_decorators.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,14 @@ async def mock_send(_, request: httpx.Request, **kwargs):
304304
305305
We want to make sure both code paths are retried.
306306
"""
307-
# Assert that the SDK issues our no-op request
307+
# Assert that the SDK issues our dummy request
308308
# returned by the BeforeRequestHook
309309
nonlocal mock_endpoint_called
310-
if request.url.host == "no-op" or "docs" in request.url.path:
310+
if request.url.host == "localhost" and "docs" in request.url.path:
311311
mock_endpoint_called = True
312312
return Response(200, request=request)
313+
elif "docs" in request.url.path:
314+
assert False, "The server URL was not set in the dummy request"
313315

314316
request_body = request.read()
315317

Diff for: gen.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ generation:
1010
auth:
1111
oAuth2ClientCredentialsEnabled: false
1212
python:
13-
version: 0.26.0
13+
version: 0.26.1
1414
additionalDependencies:
1515
dev:
1616
deepdiff: '>=6.0'

Diff for: src/unstructured_client/_hooks/custom/split_pdf_hook.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class SplitPdfHook(SDKInitHook, BeforeRequestHook, AfterSuccessHook, AfterErrorH
105105

106106
def __init__(self) -> None:
107107
self.client: Optional[HttpClient] = None
108+
self.base_url: Optional[str] = None
108109
self.async_client: Optional[AsyncHttpClient] = None
109110
self.coroutines_to_execute: dict[
110111
str, list[Coroutine[Any, Any, httpx.Response]]
@@ -156,6 +157,9 @@ def handle_request(self, request: httpx.Request) -> httpx.Response:
156157
# # Otherwise, pass the request to the default transport
157158
# return await self.base_transport.handle_async_request(request)
158159

160+
# Instead, save the base url so we can use it for our dummy request
161+
self.base_url = base_url
162+
159163
# Explicit cast to httpx.Client to avoid a typing error
160164
httpx_client = cast(httpx.Client, client)
161165
# async_httpx_client = cast(httpx.AsyncClient, async_client)
@@ -346,7 +350,7 @@ async def call_api_partial(page):
346350
# dummy_request = httpx.Request("GET", "http://no-op")
347351
return httpx.Request(
348352
"GET",
349-
"https://api.unstructuredapp.io/general/docs",
353+
f"{self.base_url}/general/docs",
350354
headers={"operation_id": operation_id},
351355
)
352356

0 commit comments

Comments
 (0)