Skip to content

Commit 6268d67

Browse files
committed
[py] bug: fix http request error validation for streaming responses
Instead of entirely skipping validation checks for streaming responses, raise any HTTP errors first, then return the response. Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
1 parent dc26f0b commit 6268d67

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

python/feldera/pipeline.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,6 @@ def query(self, query: str) -> Generator[Mapping[str, Any], None, None]:
353353
:return: A generator that yields the rows of the result as Python dictionaries.
354354
"""
355355

356-
if self.status() not in [
357-
PipelineStatus.RUNNING,
358-
PipelineStatus.PAUSED,
359-
]:
360-
raise RuntimeError("Pipeline must be running or paused to run a query")
361356
return self.client.query_as_json(self.name, query)
362357

363358
def query_parquet(self, query: str, path: str):
@@ -369,11 +364,6 @@ def query_parquet(self, query: str, path: str):
369364
:param path: The path of the parquet file.
370365
"""
371366

372-
if self.status() not in [
373-
PipelineStatus.RUNNING,
374-
PipelineStatus.PAUSED,
375-
]:
376-
raise RuntimeError("Pipeline must be running or paused to run a query")
377367
self.client.query_as_parquet(self.name, query, path)
378368

379369
def query_tabular(self, query: str) -> Generator[str, None, None]:
@@ -384,9 +374,4 @@ def query_tabular(self, query: str) -> Generator[str, None, None]:
384374
:return: A generator that yields a string representing the query result in a human-readable, tabular format.
385375
"""
386376

387-
if self.status() not in [
388-
PipelineStatus.RUNNING,
389-
PipelineStatus.PAUSED,
390-
]:
391-
raise RuntimeError("Pipeline must be running or paused to run a query")
392377
return self.client.query_as_text(self.name, query)

python/feldera/rest/_httprequests.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,7 @@ def send_request(
8383
stream=stream,
8484
)
8585

86-
if stream:
87-
return request
88-
if request.headers.get("content-type") == "text/plain":
89-
return request.text
90-
elif request.headers.get("content-type") == "application/octet-stream":
91-
return request.content
92-
93-
resp = self.__validate(request)
86+
resp = self.__validate(request, stream=stream)
9487
logging.debug("got response: %s", str(resp))
9588
return resp
9689

@@ -164,9 +157,17 @@ def __to_json(request: requests.Response) -> Any:
164157
return request.json()
165158

166159
@staticmethod
167-
def __validate(request: requests.Response) -> Any:
160+
def __validate(request: requests.Response, stream=False) -> Any:
168161
try:
169162
request.raise_for_status()
163+
164+
if stream:
165+
return request
166+
if request.headers.get("content-type") == "text/plain":
167+
return request.text
168+
elif request.headers.get("content-type") == "application/octet-stream":
169+
return request.content
170+
170171
resp = HttpRequests.__to_json(request)
171172
return resp
172173
except requests.exceptions.HTTPError as err:

python/tests/test_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_adhoc_query_text(self):
161161
TEST_CLIENT.start_pipeline(name)
162162

163163
TEST_CLIENT.push_to_pipeline(name, "tbl", "csv", data)
164-
resp = TEST_CLIENT.query(pipeline.name, "SELECT * FROM tbl", "text")
164+
resp = TEST_CLIENT.query_as_text(pipeline.name, "SELECT * FROM tbl")
165165
expected = """+----+
166166
| id |
167167
+----+
@@ -214,7 +214,7 @@ def test_adhoc_query_json(self):
214214
TEST_CLIENT.start_pipeline(name)
215215

216216
TEST_CLIENT.push_to_pipeline(name, "tbl", "csv", data)
217-
resp = TEST_CLIENT.query(pipeline.name, "SELECT * FROM tbl", "json")
217+
resp = TEST_CLIENT.query_as_json(pipeline.name, "SELECT * FROM tbl")
218218
expected = [{"id": 2}, {"id": 1}]
219219
got = list(resp)
220220

python/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)