diff --git a/jira/resources.py b/jira/resources.py index a2bb49bd5..d70c498db 100644 --- a/jira/resources.py +++ b/jira/resources.py @@ -295,19 +295,21 @@ def _get_url(self, path: str) -> str: def _validate_self_self_url(self) -> None: """In the case of a proxy, use the configured option server URL.""" - self_parsed = urlparse(self.self) - server_parsed = urlparse(self._options["server"]) - if self_parsed.netloc != server_parsed.netloc: - self.self = urlunparse( - ParseResult( - scheme=server_parsed.scheme, - netloc=server_parsed.netloc, - path=self_parsed.path, - params=self_parsed.params, - query=self_parsed.query, - fragment=self_parsed.fragment, + if getattr(self, "self", None): + self.self: str + self_parsed = urlparse(self.self) + server_parsed = urlparse(self._options["server"]) + if self_parsed.netloc != server_parsed.netloc: + self.self = urlunparse( + ParseResult( + scheme=server_parsed.scheme, + netloc=server_parsed.netloc, + path=self_parsed.path, + params=self_parsed.params, + query=self_parsed.query, + fragment=self_parsed.fragment, + ) ) - ) def update( self, @@ -1523,7 +1525,7 @@ def __init__( session: ResilientSession, raw: dict[str, Any] | None = None, ): - self.self = None + self.self = "" Resource.__init__(self, path, options, session, self.AGILE_BASE_URL) if raw: diff --git a/tests/resources/test_issue.py b/tests/resources/test_issue.py index f80722f7e..6b36e6275 100644 --- a/tests/resources/test_issue.py +++ b/tests/resources/test_issue.py @@ -347,6 +347,8 @@ def test_update_label_with_proxy(self): labelarray = ["testLabel"] fields = {"labels": labelarray} + #This simulates when your Jira server is behind a proxy + #The self address returned will be different from the configured server issue.self = f"https://foo.bar/jira/rest/api/2/issue/{issue.id}" issue.update(fields=fields) self.assertEqual(issue.fields.labels, ["testLabel"]) @@ -395,6 +397,8 @@ def test_delete_with_proxy(self): issuetype=self.test_manager.CI_JIRA_ISSUE, ) key = issue.key + #This simulates when your Jira server is behind a proxy + #The self address returned will be different from the configured server issue.self = f"https://foo.bar/jira/rest/api/2/issue/{issue.id}" issue.delete() self.assertRaises(JIRAError, self.jira.issue, key)