Skip to content

Fix ArtifactFileField.pre_save spurious rejection when MEDIA_ROOT is empty - #8076

Open
dkliban wants to merge 6 commits into
pulp:mainfrom
dkliban:GH-8041/fix-artifact-presave-empty-media-root
Open

Fix ArtifactFileField.pre_save spurious rejection when MEDIA_ROOT is empty#8076
dkliban wants to merge 6 commits into
pulp:mainfrom
dkliban:GH-8041/fix-artifact-presave-empty-media-root

Conversation

@dkliban

@dkliban dkliban commented Sep 7, 2026

Copy link
Copy Markdown
Member

Upstream contribution. Original issue: GH-8041

…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
# "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")
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread CHANGES/8041.bugfix
@@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attack of the double backticks

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).")

@dralley dralley Sep 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants