Skip to content

Commit d77ee2c

Browse files
Removed ListOptions from model amd Updated Cancel and force cancel option
1 parent a8cd985 commit d77ee2c

4 files changed

Lines changed: 2 additions & 108 deletions

File tree

src/pytfe/models/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,8 @@
149149
from .query_run import (
150150
QueryRun,
151151
QueryRunActions,
152-
QueryRunCancelOptions,
153152
QueryRunCreateOptions,
154-
QueryRunForceCancelOptions,
155153
QueryRunIncludeOpt,
156-
QueryRunList,
157154
QueryRunListOptions,
158155
QueryRunReadOptions,
159156
QueryRunSource,
@@ -435,11 +432,8 @@
435432
# Query runs
436433
"QueryRun",
437434
"QueryRunActions",
438-
"QueryRunCancelOptions",
439435
"QueryRunCreateOptions",
440-
"QueryRunForceCancelOptions",
441436
"QueryRunIncludeOpt",
442-
"QueryRunList",
443437
"QueryRunListOptions",
444438
"QueryRunReadOptions",
445439
"QueryRunSource",

src/pytfe/models/query_run.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ class QueryRunListOptions(BaseModel):
157157

158158
model_config = ConfigDict(populate_by_name=True)
159159

160-
page_number: int | None = Field(
161-
None, alias="page[number]", description="Page number to retrieve", ge=1
162-
)
163160
page_size: int | None = Field(
164161
None, alias="page[size]", description="Number of items per page", ge=1, le=100
165162
)
@@ -176,38 +173,3 @@ class QueryRunReadOptions(BaseModel):
176173
include: list[QueryRunIncludeOpt] | None = Field(
177174
None, description="List of related resources to include"
178175
)
179-
180-
181-
class QueryRunCancelOptions(BaseModel):
182-
"""Options for canceling a query run."""
183-
184-
model_config = ConfigDict(populate_by_name=True)
185-
186-
comment: str | None = Field(
187-
None, description="Optional comment about why the query run was canceled"
188-
)
189-
190-
191-
class QueryRunForceCancelOptions(BaseModel):
192-
"""Options for force canceling a query run."""
193-
194-
model_config = ConfigDict(populate_by_name=True)
195-
196-
comment: str | None = Field(
197-
None, description="Optional comment about why the query run was force canceled"
198-
)
199-
200-
201-
class QueryRunList(BaseModel):
202-
"""Represents a paginated list of query runs."""
203-
204-
model_config = ConfigDict(populate_by_name=True)
205-
206-
items: list[QueryRun] = Field(
207-
default_factory=list, description="List of query runs"
208-
)
209-
current_page: int | None = Field(None, description="Current page number")
210-
total_pages: int | None = Field(None, description="Total number of pages")
211-
prev_page: int | str | None = Field(None, description="Previous page number or URL")
212-
next_page: int | str | None = Field(None, description="Next page number or URL")
213-
total_count: int | None = Field(None, description="Total number of items")

src/pytfe/resources/query_run.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
)
1111
from ..models.query_run import (
1212
QueryRun,
13-
QueryRunCancelOptions,
1413
QueryRunCreateOptions,
15-
QueryRunForceCancelOptions,
1614
QueryRunListOptions,
1715
QueryRunReadOptions,
1816
)
@@ -152,46 +150,28 @@ def logs(self, query_run_id: str) -> io.IOBase:
152150
# Return the content as a BytesIO stream
153151
return io.BytesIO(r.content)
154152

155-
def cancel(
156-
self, query_run_id: str, options: QueryRunCancelOptions | None = None
157-
) -> None:
153+
def cancel(self, query_run_id: str) -> None:
158154
"""Cancel a query run.
159155
160156
Returns 202 on success with empty body.
161157
"""
162158
if not valid_string_id(query_run_id):
163159
raise InvalidQueryRunIDError()
164160

165-
body: dict[str, Any] | None = None
166-
if options:
167-
attrs = options.model_dump(by_alias=True, exclude_none=True)
168-
if attrs:
169-
body = {"data": {"attributes": attrs}}
170-
171161
self.t.request(
172162
"POST",
173163
f"/api/v2/queries/{query_run_id}/actions/cancel",
174-
json_body=body,
175164
)
176165

177-
def force_cancel(
178-
self, query_run_id: str, options: QueryRunForceCancelOptions | None = None
179-
) -> None:
166+
def force_cancel(self, query_run_id: str) -> None:
180167
"""Force cancel a query run.
181168
182169
Returns 202 on success with empty body.
183170
"""
184171
if not valid_string_id(query_run_id):
185172
raise InvalidQueryRunIDError()
186173

187-
body: dict[str, Any] | None = None
188-
if options:
189-
attrs = options.model_dump(by_alias=True, exclude_none=True)
190-
if attrs:
191-
body = {"data": {"attributes": attrs}}
192-
193174
self.t.request(
194175
"POST",
195176
f"/api/v2/queries/{query_run_id}/actions/force-cancel",
196-
json_body=body,
197177
)

tests/units/test_query_run.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
from pytfe.errors import InvalidQueryRunIDError, InvalidWorkspaceIDError
2222
from pytfe.models import (
2323
QueryRun,
24-
QueryRunCancelOptions,
2524
QueryRunCreateOptions,
26-
QueryRunForceCancelOptions,
2725
QueryRunIncludeOpt,
2826
QueryRunListOptions,
2927
QueryRunReadOptions,
@@ -431,26 +429,6 @@ def test_cancel_success(self, query_runs_service, mock_transport):
431429
mock_transport.request.assert_called_once_with(
432430
"POST",
433431
"/api/v2/queries/qr-123abc456def/actions/cancel",
434-
json_body=None,
435-
)
436-
437-
def test_cancel_with_comment(self, query_runs_service, mock_transport):
438-
"""Test cancellation with comment."""
439-
mock_response = Mock()
440-
mock_transport.request.return_value = mock_response
441-
442-
options = QueryRunCancelOptions(comment="Canceling due to configuration error")
443-
444-
query_runs_service.cancel("qr-123abc456def", options)
445-
446-
# Verify the request includes comment
447-
call_args = mock_transport.request.call_args
448-
assert call_args[0][0] == "POST"
449-
assert call_args[0][1] == "/api/v2/queries/qr-123abc456def/actions/cancel"
450-
json_body = call_args[1]["json_body"]
451-
assert (
452-
json_body["data"]["attributes"]["comment"]
453-
== "Canceling due to configuration error"
454432
)
455433

456434
def test_cancel_invalid_id(self, query_runs_service):
@@ -478,26 +456,6 @@ def test_force_cancel_success(self, query_runs_service, mock_transport):
478456
mock_transport.request.assert_called_once_with(
479457
"POST",
480458
"/api/v2/queries/qr-123abc456def/actions/force-cancel",
481-
json_body=None,
482-
)
483-
484-
def test_force_cancel_with_comment(self, query_runs_service, mock_transport):
485-
"""Test force cancellation with comment."""
486-
mock_response = Mock()
487-
mock_transport.request.return_value = mock_response
488-
489-
options = QueryRunForceCancelOptions(comment="Force canceling stuck query run")
490-
491-
query_runs_service.force_cancel("qr-123abc456def", options)
492-
493-
# Verify the request includes comment
494-
call_args = mock_transport.request.call_args
495-
assert call_args[0][0] == "POST"
496-
assert call_args[0][1] == "/api/v2/queries/qr-123abc456def/actions/force-cancel"
497-
json_body = call_args[1]["json_body"]
498-
assert (
499-
json_body["data"]["attributes"]["comment"]
500-
== "Force canceling stuck query run"
501459
)
502460

503461
def test_force_cancel_invalid_id(self, query_runs_service):

0 commit comments

Comments
 (0)