Skip to content

Commit

Permalink
Better handle latest (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog authored May 21, 2024
1 parent 6701505 commit 9c8b04d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Brewtils Changelog
==================

3.26.1
------
TBD

- Fixed SystemClient to revert to actual System Version when using `latest` when validation error occurs when no change in calculated latest.
Allowing support for Beer Garden >= 3.26

3.26.0
------
5/16/2024
Expand Down
18 changes: 13 additions & 5 deletions brewtils/rest/system_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def __init__(self, *args, **kwargs):
self._system_namespace = self._system_namespaces[0]
self._current_system_namespace = -1

self._use_latest = self._version_constraint.lower() == "latest"

self._always_update = kwargs.get("always_update", False)
self._timeout = kwargs.get("timeout", None)
self._max_delay = kwargs.get("max_delay", 30)
Expand Down Expand Up @@ -358,7 +360,7 @@ def create_bg_request(self, command_name, **kwargs):
_system_namespace=self._system.namespace,
_system_version=(
self._version_constraint
if self._version_constraint == "latest"
if self._use_latest
else self._system.version
),
_system_display=self._system.display_name,
Expand Down Expand Up @@ -411,6 +413,12 @@ def send_bg_request(self, *args, **kwargs):
# check for a new version and retry
try:
request = self._construct_bg_request(**kwargs)

if not self.target_self:
request = self._easy_client.create_request(
request, blocking=blocking, timeout=timeout
)

except ValidationError:
if self._system and self._version_constraint == "latest":
old_version = self._system.version
Expand All @@ -420,11 +428,11 @@ def send_bg_request(self, *args, **kwargs):
if old_version != self._system.version:
kwargs["_system_version"] = self._system.version
return self.send_bg_request(**kwargs)
elif self._use_latest:
self._use_latest = False
kwargs["_system_version"] = self._system.version
return self.send_bg_request(**kwargs)
raise
if not self.target_self:
request = self._easy_client.create_request(
request, blocking=blocking, timeout=timeout
)

# If not blocking just return the future
if not blocking:
Expand Down
6 changes: 4 additions & 2 deletions test/rest/system_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,14 @@ def test_error_no_raise(self, client, easy_client, mock_error):
assert request.status == mock_error.status
assert request.output == mock_error.output

def test_retry_send_no_different_version(self, client, easy_client):
def test_retry_send_latest_no_different_version(self, client, easy_client):

easy_client.create_request.side_effect = ValidationError

with pytest.raises(ValidationError):
client.speak()
assert easy_client.create_request.call_count == 1
assert easy_client.create_request.call_count == 2
assert not client._use_latest

def test_retry_send_different_version(
self, client, easy_client, bg_system_2, mock_success
Expand Down

0 comments on commit 9c8b04d

Please sign in to comment.