Skip to content

Commit 337472e

Browse files
dklibanclaude
andcommitted
Add NAME_FILTER_OPTIONS to FileContent relative_path filter
FileContentFilter only supported exact matching on relative_path. Use NAME_FILTER_OPTIONS to enable contains, startswith, regex, and other lookup expressions, consistent with other content filters. Fixes #7719 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e2c3f4d commit 337472e

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

CHANGES/pulp_file/7719.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `NAME_FILTER_OPTIONS` to the `relative_path` field in `FileContentFilter`, enabling contains, startswith, regex, and other lookup expressions.

pulp_file/app/viewsets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from rest_framework.generics import get_object_or_404
1010
from rest_framework.response import Response
1111

12+
from pulpcore.app.viewsets.base import NAME_FILTER_OPTIONS
1213
from pulpcore.plugin.actions import ModifyRepositoryActionMixin
1314
from pulpcore.plugin.models import (
1415
AlternateContentSource,
@@ -66,7 +67,10 @@ class FileContentFilter(ContentFilter):
6667

6768
class Meta:
6869
model = FileContent
69-
fields = ["relative_path", "sha256"]
70+
fields = {
71+
"relative_path": NAME_FILTER_OPTIONS,
72+
"sha256": ["exact"],
73+
}
7074

7175

7276
class FileContentViewSet(SingleArtifactContentUploadViewSet):

pulp_file/tests/functional/api/test_crud_content_unit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@ def test_crud_content_unit(file_bindings, random_artifact, gen_object_with_clean
3434
assert exc.value.args[0] == "'ContentFilesApi' object has no attribute 'update'"
3535

3636

37+
@pytest.mark.parallel
38+
def test_relative_path_filter_options(file_bindings, random_artifact, gen_object_with_cleanup):
39+
"""Test that relative_path supports contains, startswith, and regex filters."""
40+
path = f"packages/python/{uuid.uuid4()}/my-package-1.0.tar.gz"
41+
content_unit = gen_object_with_cleanup(
42+
file_bindings.ContentFilesApi,
43+
artifact=random_artifact.pulp_href,
44+
relative_path=path,
45+
)
46+
47+
# contains
48+
response = file_bindings.ContentFilesApi.list(relative_path__contains="my-package")
49+
assert response.count >= 1
50+
assert any(c.pulp_href == content_unit.pulp_href for c in response.results)
51+
52+
# startswith
53+
response = file_bindings.ContentFilesApi.list(relative_path__startswith="packages/python/")
54+
assert response.count >= 1
55+
assert any(c.pulp_href == content_unit.pulp_href for c in response.results)
56+
57+
# regex
58+
response = file_bindings.ContentFilesApi.list(relative_path__regex=r".*\.tar\.gz$")
59+
assert response.count >= 1
60+
assert any(c.pulp_href == content_unit.pulp_href for c in response.results)
61+
62+
# negative case — no match
63+
response = file_bindings.ContentFilesApi.list(relative_path__startswith="nonexistent-prefix/")
64+
assert not any(c.pulp_href == content_unit.pulp_href for c in response.results)
65+
66+
3767
@pytest.mark.parallel
3868
def test_same_sha256_same_relative_path_no_repo(file_bindings, random_artifact, monitor_task):
3969
artifact_attrs = {"artifact": random_artifact.pulp_href, "relative_path": str(uuid.uuid4())}

0 commit comments

Comments
 (0)