From 7470cf29d0dede60566916628984dcc8bdac9dba Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Mon, 3 Mar 2025 16:25:57 +0100 Subject: [PATCH] Work around broken v2 metadata endpoint in Pulp This patch adjusts the metadata processing to swallow 404 and handle other cases as a cache reset request. Ref: https://github.com/ansible/ansible/pull/82396#discussion_r1697523264 --- lib/ansible/galaxy/api.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py index 6765b087b35..df78fdde7c2 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -853,10 +853,18 @@ class GalaxyAPI: try: modified_date = self.get_collection_metadata(namespace, name).modified_str except GalaxyError as err: - if err.http_code != 404: + if err.http_code == 404: + # No collection found, return an empty list to keep things consistent with the various APIs + return [] + elif err.http_code != 500 or 'v3' in self.available_api_versions: raise - # No collection found, return an empty list to keep things consistent with the various APIs - return [] + + # v2 appears to have a bug on some versions, where the metadata URL is an HTTP error 500 + # since this URL is only used to handle the cache, proceed as if the cache needs to be refreshed. + modified_date = None + if '%s.%s' % (namespace, name) in modified_cache: + del modified_cache['%s.%s' % (namespace, name)] + self._set_cache() cached_modified_date = modified_cache.get('%s.%s' % (namespace, name), None) if cached_modified_date != modified_date: