pulp / pulp/pulpcore

Return 200 instead of 201 when content upload returns existing content unit

Open
#7,820 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
598
Forks
168
Avg merge
1d 4h
Merged PRs (30d)
86

Description

Problem Statement

When uploading content that already exists (duplicate), SingleArtifactContentSerializer.create() calls retrieve() and returns the existing content unit. However, the HTTP response is always 201 Created, even when no new resource was created. This is misleading.

Current Behavior

Both ContentViewSet (via CreateModelMixin) and SingleArtifactContentUploadViewSet always return 201, regardless of whether the content was newly created or retrieved from an existing duplicate.

Expected Behavior

Return 200 OK when the content unit already exists (retrieved via retrieve()), and 201 Created only when a new content unit is actually created.

Implementation Notes

SingleArtifactContentSerializer.create() already tracks a created boolean (line ~109 in content.py). This flag needs to be propagated to the viewset layer so it can choose the appropriate HTTP status code. This would benefit all plugins that implement retrieve() (pulp_rpm, pulp_maven, etc.) without requiring per-plugin changes.

Related: https://github.com/pulp/pulp_maven/issues/363

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in content.py at SingleArtifactContentSerializer.create(), where the created boolean is tracked, then trace how ContentViewSet and SingleArtifactContentUploadViewSet return responses. Verify that retrieved duplicates produce 200 OK while newly created content produces 201 Created, including behavior for plugins that implement retrieve().

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.