Skip to content

_save_prefixes_txt crashes with DoesNotExist when two domains produce identical prefixes.txt #557

Closed

Description

@git-hyagi

Description

_save_prefixes_txt crashes with MavenMetadata.DoesNotExist when two domains generate a prefixes.txt with identical content (same sha256). This makes modify_repo unusable on the second domain.

Root cause

MavenMetadata.sha256 has a global unique=True constraint (not scoped to _pulp_domain):

# pulp_maven/app/models.py
sha256 = models.CharField(max_length=64, null=False, unique=True, db_index=True)

In _save_prefixes_txt, the save-or-get pattern assumes the IntegrityError came from the domain-scoped unique_together constraint, but it actually comes from the global sha256 uniqueness:

# pulp_maven/app/tasks/__init__.py, line ~83-103
metadata_content = MavenMetadata(
    group_id="", artifact_id="", version=None,
    filename=PREFIXES_TXT_FILENAME,
    sha256=artifact.sha256,
    _pulp_domain=pulp_domain,
)
try:
    with transaction.atomic():
        metadata_content.save()
except IntegrityError:
    metadata_content = MavenMetadata.objects.get(
        group_id="", artifact_id="", version=None,
        filename=PREFIXES_TXT_FILENAME,
        sha256=artifact.sha256,
        _pulp_domain=pulp_domain,  # <-- filters by THIS domain
    )

When domain A and domain B produce prefixes.txt with identical content:

  1. Domain A's .save() succeeds — sha256 is new globally.
  2. Domain B's .save() raises IntegrityError — sha256 already exists (from domain A).
  3. Domain B's .get() filters by _pulp_domain=B, but the record belongs to domain A → DoesNotExist.

The same pattern exists in _save_metadata_content (line ~518-529), which is vulnerable to the same bug for any metadata file that happens to have identical content across domains.

How to reproduce

  1. In a multi-domain Pulp instance, create a Maven repository in domain A.
  2. Upload a single artifact with group_id="org.example" and call modify_repo to add it. This succeeds and generates a prefixes.txt containing only /org/example.
  3. In domain B, create a Maven repository and upload an artifact with the same group_id="org.example".
  4. Call modify_repo on domain B → crashes with MavenMetadata matching query does not exist.

Traceback

File ".../pulpcore/app/tasks/repository.py", line 259, in add_and_remove
    with repository.new_version(base_version=base_version) as new_version:
File ".../pulpcore/app/models/repository.py", line 1513, in __exit__
    repository.finalize_new_version(self)
File ".../pulp_maven/app/models.py", line 639, in finalize_new_version
    self._generate_metadata(new_version)
File ".../pulp_maven/app/models.py", line 1045, in _generate_metadata
    prefixes_pks = _save_prefixes_txt(current_prefixes, self.pulp_domain)
File ".../pulp_maven/app/tasks/__init__.py", line 96, in _save_prefixes_txt
    metadata_content = MavenMetadata.objects.get(
django.core.exceptions.ObjectDoesNotExist: MavenMetadata matching query does not exist.

Suggested fix

Either:

  1. Scope the sha256 uniqueness to the domain — replace the global unique=True on the sha256 field with inclusion in the unique_together constraint (which already includes _pulp_domain).

  2. Handle the cross-domain collision in the fallback — when the IntegrityError is from the global sha256 constraint, look up the existing record without the sha256 filter and update it, or share the content record across domains.

Activity

  1. added a commit that references this issue on Nov 5, 2026
    e942ff2
  2. added a commit that references this issue on Nov 5, 2026
    af07f3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions