Skip to content

feat: add PUT /{file_id}/replace endpoint for clearing file tags#479

Merged
JasonW404 merged 1 commit intomainfrom
feat/add-tag-replace-endpoint
May 6, 2026
Merged

feat: add PUT /{file_id}/replace endpoint for clearing file tags#479
JasonW404 merged 1 commit intomainfrom
feat/add-tag-replace-endpoint

Conversation

@JasonW404
Copy link
Copy Markdown
Collaborator

Summary

  • Add new API endpoint PUT /api/annotation/task/{file_id}/replace to fully replace file annotation tags
  • Empty tag list now clears all tags (previously partial update kept them unchanged)
  • Supports both simplified and full tag formats with auto-conversion via template

Problem

The existing PUT /{file_id} endpoint performs a partial update (merge), so passing an empty tag list [] would not clear the tags - it would just keep the existing tags unchanged.

Solution

Added a new PUT /{file_id}/replace endpoint that performs full replacement:

  • Empty list {"tags": []} → clears all tags
  • New tags → completely replaces existing tags (no merge)

Changes

File Change
service.py Add replace_file_tags() method
task.py Add PUT /{file_id}/replace endpoint

API Usage

# Clear all tags
PUT /api/annotation/task/{file_id}/replace
{"tags": []}

# Replace with new tags
PUT /api/annotation/task/{file_id}/replace
{"tags": [{"from_name": "label", "to_name": "image", "values": ["cat"]}]}

Add new API endpoint to fully replace (not merge) file annotation tags.
- Empty tag list now clears all tags (partial update kept them)
- Supports both simplified and full tag formats with auto-conversion
- Addresses bug where tags couldn't be deleted via empty list
Copilot AI review requested due to automatic review settings May 6, 2026 02:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new FastAPI endpoint to support full replacement of a dataset file’s annotation tags (including clearing tags by submitting an empty list), complementing the existing partial-merge update behavior.

Changes:

  • Added DatasetManagementService.replace_file_tags() to overwrite DatasetFiles.tags and update tags_updated_at.
  • Added PUT /api/annotation/task/{file_id}/replace endpoint to perform full tag replacement (supports template-based simplified→full tag conversion).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
runtime/datamate-python/app/module/dataset/service/service.py Adds service method to fully replace a file’s tags (with optional template-driven conversion).
runtime/datamate-python/app/module/annotation/interface/task.py Adds new PUT /{file_id}/replace route that calls the service method and returns updated tags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +354 to +356
result = await db.execute(
select(DatasetFiles).where(DatasetFiles.id == file_id)
)
@JasonW404 JasonW404 merged commit 4ab0d98 into main May 6, 2026
12 checks passed
@JasonW404 JasonW404 deleted the feat/add-tag-replace-endpoint branch May 6, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants