diff --git a/pynetbox/core/query.py b/pynetbox/core/query.py index 335ddd7a..6c70994f 100644 --- a/pynetbox/core/query.py +++ b/pynetbox/core/query.py @@ -140,6 +140,7 @@ def __init__( private_key=None, session_key=None, ssl_verify=True, + url=None, ): """ Instantiates a new Request object diff --git a/pynetbox/core/response.py b/pynetbox/core/response.py index 57fac7c4..33703e81 100644 --- a/pynetbox/core/response.py +++ b/pynetbox/core/response.py @@ -384,8 +384,8 @@ def save(self): if diff: serialized = self.serialize() req = Request( - key=self.id, - base=self.endpoint.url, + key=self.id if not self.url else None, + base=self.url or self.endpoint.url, token=self.api.token, session_key=self.api.session_key, ssl_verify=self.api.ssl_verify, @@ -433,8 +433,8 @@ def delete(self): >>> """ req = Request( - key=self.id, - base=self.endpoint.url, + key=self.id if not self.url else None, + base=self.url or self.endpoint.url, token=self.api.token, session_key=self.api.session_key, ssl_verify=self.api.ssl_verify, diff --git a/tests/unit/test_response.py b/tests/unit/test_response.py index eea9c5db..a50d3723 100644 --- a/tests/unit/test_response.py +++ b/tests/unit/test_response.py @@ -139,3 +139,21 @@ def test_compare(self): test2 = Record({}, None, endpoint2) test2.id = 1 self.assertEqual(test1, test2) + + def test_nested_write(self): + app = Mock() + app.token = 'abc123' + endpoint = Mock() + endpoint.name = "test-endpoint" + test = Record({ + 'id': 123, + 'name': 'test', + 'child': { + 'id': 321, + 'name': 'test123', + 'url': 'http://localhost:8080/test', + }, + }, app, endpoint) + test.child.name = 'test321' + test.child.save() + self.assertEqual(app.http_session.patch.call_args[0][0], "http://localhost:8080/test/")