Skip to content

Commit 59a2c43

Browse files
committed
Remove force-sorting for query_tickets API and mention sorting in README
1 parent 5a33879 commit 59a2c43

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ TracApiVersion(epoch=1, major=2, minor=0)
3131
datetime.datetime(2025, 2, 27, 13, 37, 11, 171873, tzinfo=TzInfo(UTC))
3232
```
3333

34+
> [!IMPORTANT]
35+
> Trac APIs (e.g. `query_tickets`) do not return IDs and/or objects sorted in alphanumeric order!
36+
>
37+
> They can either be returned in a custom order (such as priority levels) or grouped by certain fields (such as ticket IDs). If you want to iterate on the objects in a particular order, always remember to sort them appropriately after you call the API.
38+
3439
### Customizing models
3540

3641
#### Changing default string type

src/trac_rpc/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def query_tickets(self, query: str = "", per_page: int = 0, page_number: int | N
145145
*((f"page={page_number}",) if page_number is not None else ()),
146146
f"max={per_page}",
147147
)
148-
return sorted(self._request(TracRequest(method="ticket.query", params=["&".join(pieces)]), list[int]))
148+
return self._request(TracRequest(method="ticket.query", params=["&".join(pieces)]), list[int])
149149

150150
def get_ticket_attachments(self, ticket_id: int) -> TracTicketAttachments:
151151
"""

tests/test_methods.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def test_query_tickets(kwargs: dict, expected: str, api_client: ApiClient, respx
2525
respx_mock.post().mock(
2626
return_value=httpx.Response(
2727
status_code=httpx.codes.OK,
28-
text="""{"error": null, "result": [1, 2, 3], "id": null}""",
28+
text="""{"error": null, "result": [3, 2, 1], "id": null}""",
2929
)
3030
)
3131

3232
def get_last_request_params() -> str:
3333
(param,) = json.loads(respx_mock.calls.last.request.content)["params"]
3434
return param
3535

36-
assert api_client.query_tickets(**kwargs) == [1, 2, 3]
36+
assert sorted(api_client.query_tickets(**kwargs)) == [1, 2, 3]
3737
assert get_last_request_params() == expected
3838

3939

0 commit comments

Comments
 (0)