@@ -79,6 +79,24 @@ def content_handler(self, path):
7979 name = None
8080 version = None
8181 domain = get_domain ()
82+
83+ # Resolve the repo version and publication for this distribution.
84+ # The behavior of pulp_python differs from pulpcore here in that it always looks
85+ # for a publication even though distribution.SERVE_FROM_PUBLICATION = False
86+ publication = self .publication
87+ repo_version = self .repository_version
88+ if publication :
89+ repo_version = publication .repository_version
90+ elif self .repository :
91+ repo_version = self .repository .latest_version ()
92+ if not publication and repo_version :
93+ try :
94+ publication = Publication .objects .filter (
95+ repository_version = repo_version , complete = True
96+ ).latest ("pulp_created" )
97+ except ObjectDoesNotExist :
98+ pass
99+
82100 if path .match ("pypi/*/*/json" ):
83101 version = path .parts [2 ]
84102 name = path .parts [1 ]
@@ -88,13 +106,7 @@ def content_handler(self, path):
88106 # Temporary fix for PublishedMetadata not being properly served from remote storage
89107 # https://github.com/pulp/pulp_python/issues/413
90108 if domain .storage_class != "pulpcore.app.models.storage.FileSystem" :
91- if self .publication or self .repository :
92- try :
93- publication = self .publication or Publication .objects .filter (
94- repository_version = self .repository .latest_version ()
95- ).latest ("pulp_created" )
96- except ObjectDoesNotExist :
97- return None
109+ if publication :
98110 if len (path .parts ) == 2 :
99111 path = PurePath (f"simple/{ canonicalize_name (path .parts [1 ])} " )
100112 rel_path = f"{ path } /index.html"
@@ -112,10 +124,10 @@ def content_handler(self, path):
112124 headers = {"Content-Type" : "text/html" }
113125 return ArtifactResponse (ca .artifact , headers = headers )
114126
115- if name :
127+ if name and repo_version :
116128 normalized = canonicalize_name (name )
117129 package_content = PythonPackageContent .objects .filter (
118- pk__in = self . publication . repository_version .content , name__normalize = normalized
130+ pk__in = repo_version .content , name__normalize = normalized
119131 )
120132 # TODO Change this value to the Repo's serial value when implemented
121133 headers = {PYPI_LAST_SERIAL : str (PYPI_SERIAL_CONSTANT )}
0 commit comments