-
Notifications
You must be signed in to change notification settings - Fork 53
Raise TaskResourceNotFound instead of bare DoesNotExist in tasks #2439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0eb7f54
cf8d2dd
8761fe6
4a22336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Raised a proper ``PulpException`` subclass instead of a bare ``Exception`` when building or pushing an OCI image fails, so the error is not sanitized away by pulpcore in a future release. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Raised a proper ``PulpException`` subclass instead of a bare Django ``DoesNotExist`` when a task's referenced object (repository, remote, manifest, signing service, etc.) no longer exists, so the error is not sanitized away by pulpcore in a future release. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| from rest_framework.exceptions import APIException, NotFound, ParseError | ||
|
|
||
| from pulpcore.plugin.exceptions import PulpException | ||
|
|
||
|
|
||
| class BadGateway(APIException): | ||
| status_code = 502 | ||
|
|
@@ -162,6 +164,39 @@ def __init__(self, digest): | |
| ) | ||
|
|
||
|
|
||
| class TaskResourceNotFound(PulpException): | ||
| """Exception to signal that a resource a task depends on no longer exists. | ||
|
|
||
| Tasks look up their arguments' referenced objects by pk. If that object was | ||
| deleted between dispatch and execution (e.g. by a racing delete), a bare Django | ||
| DoesNotExist is not a PulpException, which pulpcore's task executor logs as | ||
| deprecated and will sanitize away in a future release. Raise this instead so the | ||
| real reason is preserved on the task result. | ||
| """ | ||
|
|
||
| error_code = "PLP_CONTAINER_TASK_RESOURCE_MISSING" | ||
|
|
||
| def __init__(self, message): | ||
| """Initialize the exception with a description of the missing resource.""" | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return self.message | ||
|
|
||
|
|
||
| class ContainerBuildError(PulpException): | ||
| """Exception to signal that building or pushing an OCI image failed.""" | ||
|
|
||
| error_code = "PLP_CONTAINER_BUILD_0001" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jobselko What did we decide for the nomenclature of error codes?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3 uppercase letters/_ , followed by 4 leading-zero digits, so |
||
|
|
||
| def __init__(self, message): | ||
| """Initialize the exception with the decoded stderr of the failed podman command.""" | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return self.message | ||
|
|
||
|
|
||
| class InvalidRequest(ParseError): | ||
| """An exception to render an HTTP 400 response.""" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
|
|
||
|
|
||
| @pytest.fixture | ||
| def cdomain_factory(domain_factory, pulpcore_bindings): | ||
| def cdomain_factory(domain_factory, pulpcore_bindings, container_bindings): | ||
| domains = [] | ||
|
|
||
| def _domain_factory(*args, **kwargs): | ||
|
|
@@ -22,6 +22,14 @@ def _domain_factory(*args, **kwargs): | |
| yield _domain_factory | ||
|
|
||
| for domain in domains: | ||
| # ContainerNamespace has a PROTECT FK to Domain, so it must be cleared before | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would copy the fix I am adding here: https://github.com/pulp/pulp_container/pull/2424/changes#diff-5287a8b917dfa3076a52a1b5bdfc8ce254b5d74ecbddf6ad08179904c5e91649R30 |
||
| # domain_factory's own teardown deletes the domain, or that delete raises | ||
| # ProtectedError. Some tests already clean their own namespace up via | ||
| # add_to_cleanup; re-querying here is a no-op for those and a safety net for | ||
| # any test (e.g. one that creates multiple distributions) that doesn't. | ||
| namespaces = container_bindings.PulpContainerNamespacesApi.list(pulp_domain=domain.name) | ||
| for namespace in namespaces.results: | ||
| container_bindings.PulpContainerNamespacesApi.delete(namespace.pulp_href) | ||
| guards = pulpcore_bindings.ContentguardsContentRedirectApi.list(pulp_domain=domain.name) | ||
| for guard in guards.results: | ||
| pulpcore_bindings.ContentguardsContentRedirectApi.delete(guard.pulp_href) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelogs are rendered in markdown so use single ticks.