Repository navigation
feat: remove the background while uploading - #277
TheBlackSide243 wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideIntroduces a remembered upload-dialog switch for automatic background removal across single, bulk, and deferred uploads, with backend job chaining that tags the cleaned image—or the original image if removal fails—so uploads remain AI-processed. Sequence diagram for upload background removal and taggingsequenceDiagram
participant User
participant UploadDialog
participant ItemsAPI
participant ImageWorker
participant TaggingWorker
User->>UploadDialog: Select removeBackground
UploadDialog->>ItemsAPI: POST /items or POST /items/bulk
ItemsAPI->>ImageWorker: remove_item_background_job(item_id, bg_color_hex, full_image_path)
ImageWorker->>ImageWorker: remove_background
alt Background removal succeeds
ImageWorker->>TaggingWorker: tag_item_image(item_id, cleaned_image_path)
else Background removal fails
ImageWorker->>TaggingWorker: tag_item_image(item_id, original_image_path)
end
TaggingWorker-->>User: Upload remains AI-processed
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="backend/app/api/items.py" line_range="228" />
<code_context>
primary_color: str | None = Form(None),
favorite: bool = Form(False),
skip_ai: bool = Form(False),
+ remove_background: bool = Form(False),
) -> ItemResponse:
# Validate and process image
</code_context>
<issue_to_address>
**Requested background removal is skipped**
When the user requests background removal while AI tagging is skipped or disabled, the upload handlers call `_queue_upload_processing` only when `do_auto_tag` is true; otherwise they mark the item ready without queuing removal. The selected option is silently ignored, and the uploaded image keeps its original background.
Queue background removal whenever it is requested, independently of automatic tagging, and add tagging only when `do_auto_tag` is true.
Also at `backend/app/api/items.py:303-305`, `backend/app/api/items.py:326-328`, `backend/app/api/items.py:474-476`, `frontend/components/add-item-dialog.tsx:535-541`.
</issue_to_address>
### Comment 2
<location path="backend/tests/test_upload_background.py" line_range="80" />
<code_context>
+ headers=auth_headers,
+ )
+ assert response.status_code == 201
+ assert redis.enqueue_job.call_args.args[0] == "tag_item_image"
+
+
</code_context>
<issue_to_address>
**Extra jobs go undetected**
When the bulk endpoint enqueues a tagging job followed by an additional background-removal job when the option is absent, `test_without_the_option_only_tags` checks only `call_args.args[0]` (line 80), so it passes when the bulk upload first queues tagging and then also queues background removal; the test does not establish that it only tags.
Assert the enqueue call count is one and that its arguments and queue name are the expected tagging job.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and when enabled—which is the default for new browser preferences—the worker replaces the stored item image with a white-background version before tagging. Reverting stops future processing but does not restore images already changed; the saved original-image path makes those changes bounded and repairable.
Blocking findings: backend/app/api/items.py:228, backend/tests/test_upload_background.py:80
| primary_color: str | None = Form(None), | ||
| favorite: bool = Form(False), | ||
| skip_ai: bool = Form(False), | ||
| remove_background: bool = Form(False), |
There was a problem hiding this comment.
🟡 Medium · Requested background removal is skipped
When the user requests background removal while AI tagging is skipped or disabled, the upload handlers call _queue_upload_processing only when do_auto_tag is true; otherwise they mark the item ready without queuing removal. The selected option is silently ignored, and the uploaded image keeps its original background.
Queue background removal whenever it is requested, independently of automatic tagging, and add tagging only when do_auto_tag is true.
Also at backend/app/api/items.py:303-305, backend/app/api/items.py:326-328, backend/app/api/items.py:474-476, frontend/components/add-item-dialog.tsx:535-541.
Prompt for AI agents
In `backend/app/api/items.py` at line 228:
**Requested background removal is skipped**
When the user requests background removal while AI tagging is skipped or disabled, the upload handlers call `_queue_upload_processing` only when `do_auto_tag` is true; otherwise they mark the item ready without queuing removal. The selected option is silently ignored, and the uploaded image keeps its original background.
Queue background removal whenever it is requested, independently of automatic tagging, and add tagging only when `do_auto_tag` is true.
Also at `backend/app/api/items.py:303-305`, `backend/app/api/items.py:326-328`, `backend/app/api/items.py:474-476`, `frontend/components/add-item-dialog.tsx:535-541`.| headers=auth_headers, | ||
| ) | ||
| assert response.status_code == 201 | ||
| assert redis.enqueue_job.call_args.args[0] == "tag_item_image" |
There was a problem hiding this comment.
🟡 Medium · Extra jobs go undetected
When the bulk endpoint enqueues a tagging job followed by an additional background-removal job when the option is absent, test_without_the_option_only_tags checks only call_args.args[0] (line 80), so it passes when the bulk upload first queues tagging and then also queues background removal; the test does not establish that it only tags.
Assert the enqueue call count is one and that its arguments and queue name are the expected tagging job.
Prompt for AI agents
In `backend/tests/test_upload_background.py` at line 80:
**Extra jobs go undetected**
When the bulk endpoint enqueues a tagging job followed by an additional background-removal job when the option is absent, `test_without_the_option_only_tags` checks only `call_args.args[0]` (line 80), so it passes when the bulk upload first queues tagging and then also queues background removal; the test does not establish that it only tags.
Assert the enqueue call count is one and that its arguments and queue name are the expected tagging job.The upload handlers queued background removal only together with AI tagging, so with tagging skipped or disabled the option was silently ignored. The removal is now queued on its own and the worker marks the item ready; a failed enqueue no longer strands the item in processing. The 'only tags' test asserts the single tagging job and its queue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Description
Adds a "Remove the background automatically" switch to the upload dialog (single and bulk). When
it is on, the new item goes to the image worker first and the AI tags the cleaned-up photo
afterwards, so the user does not have to run the removal item by item later.
remove_backgroundform field onPOST /itemsandPOST /items/bulk.remove_item_background_jobtakes an optionalthen_tag_path: when set it queues tagging oncethe removal is done; a failed removal still hands the item to tagging with its original photo,
so an upload is never left untagged.
This is one of a set of small, independent PRs (each branches from
mainand can be reviewed ordropped on its own); they only overlap in the nav/router registration lines.
Type of Change
Checklist
Testing
ruff check,ruff format --check, migration heads check and the full pytest suite on top of currentmain(2031 passed).npm run lint,i18n:check,vocab:check,tsc --noEmitand vitest (693 passed).Test Environment
🤖 Generated with Claude Code
Summary by Sourcery
Enable automatic background removal during image uploads while preserving reliable downstream tagging.
New Features:
Enhancements:
Tests:
Chores: