Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/167.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a :class:`ReferenceError` when chaining a request off a temporary client, e.g. ``SpaceTrackClient(...).basicspacedata.gp(...)``.
4 changes: 1 addition & 3 deletions src/spacetrack/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,7 @@ class _ControllerProxy:
"""Proxies request class methods with a preset request controller."""

def __init__(self, client, controller):
# The client will cache _ControllerProxy instances, so only store
# a weak reference to it.
self.client = weakref.proxy(client)
self.client = client
self.controller = controller

def __getattr__(self, attr):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_spacetrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ def test_controller_spacetrack_methods(client):
assert mock_generic_request.call_args == expected


def test_controller_proxy_keeps_client_alive(httpx2_mock):
# A _ControllerProxy used to hold only a weak reference, so using a
# proxy after the client's last strong reference was dropped raised
# ReferenceError.
with patch.object(SpaceTrackClient, "generic_request") as mock_generic_request:
SpaceTrackClient("identity", "password").basicspacedata.gp()

mock_generic_request.assert_called_once()


def test_authenticate(httpx2_mock):
def request_callback(request):
if b"wrongpassword" in request.content:
Expand Down