-
-
Notifications
You must be signed in to change notification settings - Fork 44
[FEAT] Add POST /datasets/untag endpoint #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,13 +48,46 @@ def tag_dataset( | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| @router.post( | ||||||||||||||||||||||||||||||||
| path="/untag", | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| def untag_dataset( | ||||||||||||||||||||||||||||||||
| data_id: Annotated[int, Body()], | ||||||||||||||||||||||||||||||||
| tag: Annotated[str, SystemString64], | ||||||||||||||||||||||||||||||||
| user: Annotated[User | None, Depends(fetch_user)] = None, | ||||||||||||||||||||||||||||||||
| expdb_db: Annotated[Connection, Depends(expdb_connection)] = None, | ||||||||||||||||||||||||||||||||
| ) -> dict[str, dict[str, Any]]: | ||||||||||||||||||||||||||||||||
| if user is None: | ||||||||||||||||||||||||||||||||
| raise create_authentication_failed_error() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| tags = database.datasets.get_tags_for(data_id, expdb_db) | ||||||||||||||||||||||||||||||||
| if tag.casefold() not in [t.casefold() for t in tags]: | ||||||||||||||||||||||||||||||||
| raise create_tag_not_found_error(data_id, tag) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| database.datasets.untag(data_id, tag, connection=expdb_db) | ||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||
| "data_untag": {"id": str(data_id)}, | ||||||||||||||||||||||||||||||||
|
Comment on lines
+63
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the canonical stored tag for delete to avoid false-success on mixed-case input. Validation is case-insensitive, but deletion uses the raw input. On a case-sensitive collation, this can return success without removing anything. 💡 Suggested fix- tags = database.datasets.get_tags_for(data_id, expdb_db)
- if tag.casefold() not in [t.casefold() for t in tags]:
+ tags = database.datasets.get_tags_for(data_id, expdb_db)
+ matching_tag = next((existing for existing in tags if existing.casefold() == tag.casefold()), None)
+ if matching_tag is None:
raise create_tag_not_found_error(data_id, tag)
- database.datasets.untag(data_id, tag, connection=expdb_db)
+ database.datasets.untag(data_id, matching_tag, connection=expdb_db)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def create_authentication_failed_error() -> HTTPException: | ||||||||||||||||||||||||||||||||
| return HTTPException( | ||||||||||||||||||||||||||||||||
| status_code=HTTPStatus.PRECONDITION_FAILED, | ||||||||||||||||||||||||||||||||
| detail={"code": "103", "message": "Authentication failed"}, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def create_tag_not_found_error(data_id: int, tag: str) -> HTTPException: | ||||||||||||||||||||||||||||||||
| return HTTPException( | ||||||||||||||||||||||||||||||||
| status_code=HTTPStatus.INTERNAL_SERVER_ERROR, | ||||||||||||||||||||||||||||||||
| detail={ | ||||||||||||||||||||||||||||||||
| "code": "474", | ||||||||||||||||||||||||||||||||
| "message": "Entity not tagged by this tag.", | ||||||||||||||||||||||||||||||||
| "additional_information": f"id={data_id}; tag={tag}", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def create_tag_exists_error(data_id: int, tag: str) -> HTTPException: | ||||||||||||||||||||||||||||||||
| return HTTPException( | ||||||||||||||||||||||||||||||||
| status_code=HTTPStatus.INTERNAL_SERVER_ERROR, | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Case-insensitive existence check but case-sensitive delete can lead to silent no-op.
The membership check uses
casefold()butuntagreceives the rawtag. If the stored tag differs only by case (e.g. "Foo" vs "foo"), the check can succeed while theDELETEaffects 0 rows (depending on DB collation), so the endpoint reports success without untagging. Normalize the tag consistently for both check and delete, or enforce a canonical casing in storage so their behavior matches.