Fix ArtifactFileField.pre_save spurious rejection when MEDIA_ROOT is empty - #8076
Open
dkliban wants to merge 6 commits into
Open
Fix ArtifactFileField.pre_save spurious rejection when MEDIA_ROOT is empty#8076dkliban wants to merge 6 commits into
dkliban wants to merge 6 commits into
Conversation
…empty
When MEDIA_ROOT is "" (object-storage backends such as S3/Azure),
os.path.join("", "artifact") == "artifact", causing any upload whose
filename starts with "artifact" to be falsely detected as already
residing in artifact storage, raising ValueError (→ HTTP 500).
Guard the check with bool(settings.MEDIA_ROOT) so that an empty
MEDIA_ROOT (object-storage condition) always evaluates
is_in_artifact_storage as False.
Fixes: pulp#8041
dralley
reviewed
Sep 8, 2026
| # "artifact" would be falsely detected as already residing in artifact storage. | ||
| is_in_artifact_storage = bool(settings.MEDIA_ROOT) and file.name.startswith( | ||
| os.path.join(settings.MEDIA_ROOT, "artifact") | ||
| ) |
Contributor
There was a problem hiding this comment.
Is short-circuiting actually what we want here? MEDIA_ROOT is always empty on S3 and Azure (I think) so how does it determine if an artifact exists with those backends?
dralley
reviewed
Sep 8, 2026
| @@ -0,0 +1 @@ | |||
| Fixed ``ArtifactFileField.pre_save`` spuriously rejecting artifact uploads whose filenames start with ``artifact`` when ``MEDIA_ROOT`` is empty (S3/Azure object-storage backends). The ``startswith`` guard now short-circuits when ``MEDIA_ROOT`` is empty, preventing false detection of fresh uploads as already-stored artifacts. | |||
Contributor
There was a problem hiding this comment.
attack of the double backticks
dralley
reviewed
Sep 8, 2026
| skipped to avoid false positives. | ||
| """ | ||
| if pulp_settings.MEDIA_ROOT: | ||
| pytest.skip("Bug GH-8041 only affects backends where MEDIA_ROOT is empty (S3/Azure).") |
Contributor
There was a problem hiding this comment.
It definitely shouldn't be in a file named pulpcore/tests/functional/api/test_artifact_presave_gh8041.py
I'm not sure I like having it so narrowly scoped either. TBH for such a specific bug we probably do not need a regression test, but more testing in general would be welcome if there are gaps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstream contribution. Original issue: GH-8041