From b5cb17fd35f98d66e14c98d713f8cdaedd6eaf29 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Tue, 13 Aug 2024 00:00:54 +0200 Subject: [PATCH] Fix error in safe_calls_only without fake_mode When fake mode was not explicitely selected complaining about unsafe calls in fake_mode is not nice. Instead, we fall back to the original error message in that case. fixes #1037 --- CHANGES/pulp-glue/1037.bugfix | 1 + pulp-glue/pulp_glue/common/context.py | 7 +++++-- pulp-glue/pulp_glue/core/context.py | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 CHANGES/pulp-glue/1037.bugfix diff --git a/CHANGES/pulp-glue/1037.bugfix b/CHANGES/pulp-glue/1037.bugfix new file mode 100644 index 000000000..82ebded8e --- /dev/null +++ b/CHANGES/pulp-glue/1037.bugfix @@ -0,0 +1 @@ +Fixed an error where safemode wrongly complained to be in `fake_mode`. diff --git a/pulp-glue/pulp_glue/common/context.py b/pulp-glue/pulp_glue/common/context.py index d82789113..a60d0e6a8 100644 --- a/pulp-glue/pulp_glue/common/context.py +++ b/pulp-glue/pulp_glue/common/context.py @@ -378,8 +378,11 @@ def call( body=body, validate_body=validate_body, ) - except UnsafeCallError: - raise NotImplementedFake(f"Operation {operation_id} was attempted in fake mode.") + except UnsafeCallError as e: + if self.fake_mode: + raise NotImplementedFake(f"Operation {operation_id} was attempted in fake mode.") + else: + raise PulpException(str(e)) except OpenAPIError as e: raise PulpException(str(e)) except HTTPError as e: diff --git a/pulp-glue/pulp_glue/core/context.py b/pulp-glue/pulp_glue/core/context.py index c574ea00b..a3ddb549c 100644 --- a/pulp-glue/pulp_glue/core/context.py +++ b/pulp-glue/pulp_glue/core/context.py @@ -288,7 +288,11 @@ def cleanup(self, body: t.Optional[t.Dict[str, t.Any]] = None) -> t.Any: else: if body: self.pulp_ctx.needs_plugin(PluginRequirement("core", specifier=">=3.14.0")) - result = self.pulp_ctx.call("orphans_delete") + if not self.pulp_ctx.fake_mode: + result = self.pulp_ctx.call("orphans_delete") + else: + # Do we need something better? + result = {} return result