Skip to content

fix(python): call _history_error_envelope on the class - #7

Open
Dusk1e wants to merge 1 commit into
Bulk-trade:mainfrom
Dusk1e:fix/history-error-envelope-call
Open

fix(python): call _history_error_envelope on the class#7
Dusk1e wants to merge 1 commit into
Bulk-trade:mainfrom
Dusk1e:fix/history-error-envelope-call

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Aug 12, 2026

Copy link
Copy Markdown

Summary

_get_history_page calls _history_error_envelope(...) as a bare name, but f5f3bf8 moved that helper from module scope into BulkHttpClient as a @staticmethod. Class-body names are not in scope inside method bodies, so the call resolves against globals, finds nothing, and every non-2xx history response raises

NameError: name '_history_error_envelope' is not defined

instead of the intended HistoryHttpError. Callers that catch HistoryHttpError — the documented contract — never see it, and the status code and error envelope are lost.

All six public history readers go through _get_history_page, so all six are affected: get_fills_page, get_positions_page, get_funding_page, get_orders_page, get_activity_page, get_risk_page.

tests/test_history_http.py already covers the intended behaviour and fails on main:

$ python -m pytest tests/test_history_http.py -q
bulk_api/api/bulk_http.py:760: NameError

SUBFAILED(status=502) HistoryHttpTests::test_history_non_contract_errors_preserve_status_with_bounded_fallback
SUBFAILED(status=503) HistoryHttpTests::test_history_non_contract_errors_preserve_status_with_bounded_fallback
SUBFAILED(status=418) HistoryHttpTests::test_history_non_contract_errors_preserve_status_with_bounded_fallback
FAILED HistoryHttpTests::test_history_non_success_preserves_structured_status_and_body
4 failed, 13 passed, 26 subtests passed

Changes

Qualify the call with self. One line; no behaviour change on the success path, and the helper itself is unchanged.

Verification

$ python -m pytest tests/test_history_http.py -q
14 passed, 29 subtests passed

The existing tests already assert the parts that were unreachable — that the status code survives, that a well-formed {"error": {code, message}} body is preserved, and that an oversized or malformed body falls back to the HISTORY_HTTP_ERROR envelope.

I also checked the rest of bulk_api for the same pattern — a call to a bare name that only exists as a method on the enclosing class — and this was the only occurrence.

f5f3bf8 moved _history_error_envelope from module scope into BulkHttpClient
as a staticmethod, but the call site in _get_history_page stayed a bare name.
Class-body names are not in scope inside method bodies, so every non-2xx
history response raised NameError instead of HistoryHttpError.

This affects get_fills_page, get_positions_page, get_funding_page,
get_orders_page, get_activity_page and get_risk_page.

tests/test_history_http.py already covers the intended behaviour and fails
on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant