Skip to content

Commit

Permalink
fix: Use configured server_url for split page dummy request (#192)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awalker4 authored Oct 12, 2024
1 parent 18a1309 commit eaa7619
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.26.1

### Enhancements

### Features

### Fixes
* Use the configured server_url for our split page "dummy" request

## 0.26.0

### Enhancements
Expand Down
6 changes: 4 additions & 2 deletions _test_unstructured_client/integration/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ async def mock_send(_, request: httpx.Request, **kwargs):
We want to make sure both code paths are retried.
"""
# Assert that the SDK issues our no-op request
# Assert that the SDK issues our dummy request
# returned by the BeforeRequestHook
nonlocal mock_endpoint_called
if request.url.host == "no-op" or "docs" in request.url.path:
if request.url.host == "localhost" and "docs" in request.url.path:
mock_endpoint_called = True
return Response(200, request=request)
elif "docs" in request.url.path:
assert False, "The server URL was not set in the dummy request"

request_body = request.read()

Expand Down
2 changes: 1 addition & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
python:
version: 0.26.0
version: 0.26.1
additionalDependencies:
dev:
deepdiff: '>=6.0'
Expand Down
6 changes: 5 additions & 1 deletion src/unstructured_client/_hooks/custom/split_pdf_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class SplitPdfHook(SDKInitHook, BeforeRequestHook, AfterSuccessHook, AfterErrorH

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

# Instead, save the base url so we can use it for our dummy request
self.base_url = base_url

# Explicit cast to httpx.Client to avoid a typing error
httpx_client = cast(httpx.Client, client)
# async_httpx_client = cast(httpx.AsyncClient, async_client)
Expand Down Expand Up @@ -346,7 +350,7 @@ async def call_api_partial(page):
# dummy_request = httpx.Request("GET", "http://no-op")
return httpx.Request(
"GET",
"https://api.unstructuredapp.io/general/docs",
f"{self.base_url}/general/docs",
headers={"operation_id": operation_id},
)

Expand Down

0 comments on commit eaa7619

Please sign in to comment.