-
Notifications
You must be signed in to change notification settings - Fork 17.9k
fix(sqllab): reject blank saved query and dataset names #41624
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
Changes from all commits
b7a7dbb
9bd7b93
eb98cdf
1fe18cb
21b7696
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 |
|---|---|---|
|
|
@@ -677,6 +677,69 @@ def test_create_saved_query(self): | |
| db.session.delete(model) | ||
| db.session.commit() | ||
|
|
||
| def test_create_saved_query_blank_label(self) -> None: | ||
| """ | ||
| Saved Query API: Test create rejects blank/whitespace-only labels | ||
| """ | ||
| example_db = get_example_database() | ||
| self.login(ADMIN_USERNAME) | ||
| uri = "api/v1/saved_query/" | ||
|
|
||
| for label in ("", " ", "\t\n"): | ||
| post_data = { | ||
| "schema": "schema1", | ||
| "label": label, | ||
| "description": "some description", | ||
| "sql": "SELECT col1, col2 from table1", | ||
| "db_id": example_db.id, | ||
| } | ||
|
Comment on lines
+689
to
+695
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. Suggestion: Add an explicit type annotation for this request payload dictionary to satisfy the type-hint requirement for relevant local variables. [custom_rule] Severity Level: Minor Why it matters? 🤔The new test code introduces a local dictionary without any type annotation, and the rule explicitly requires type hints for relevant variables that can be annotated. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/integration_tests/queries/saved_queries/api_tests.py
**Line:** 689:695
**Comment:**
*Custom Rule: Add an explicit type annotation for this request payload dictionary to satisfy the type-hint requirement for relevant local variables.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| rv = self.client.post(uri, json=post_data) | ||
| data = json.loads(rv.data.decode("utf-8")) | ||
| assert rv.status_code == 422 | ||
| assert "label" in data["message"] | ||
|
|
||
| def test_create_saved_query_strips_label(self) -> None: | ||
| """ | ||
| Saved Query API: Test create trims surrounding whitespace from labels | ||
| """ | ||
| example_db = get_example_database() | ||
| self.login(ADMIN_USERNAME) | ||
| uri = "api/v1/saved_query/" | ||
|
|
||
| post_data = { | ||
| "schema": "schema1", | ||
| "label": " label1 ", | ||
| "description": "some description", | ||
| "sql": "SELECT col1, col2 from table1", | ||
| "db_id": example_db.id, | ||
| } | ||
|
Comment on lines
+709
to
+715
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. Suggestion: Add a concrete type annotation for this local dictionary used in the test input so the new code fully complies with required typing. [custom_rule] Severity Level: Minor Why it matters? 🤔This is another newly added local dictionary in Python code with no type hint, which matches the rule’s requirement to annotate relevant variables in modified code. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/integration_tests/queries/saved_queries/api_tests.py
**Line:** 709:715
**Comment:**
*Custom Rule: Add a concrete type annotation for this local dictionary used in the test input so the new code fully complies with required typing.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| rv = self.client.post(uri, json=post_data) | ||
| data = json.loads(rv.data.decode("utf-8")) | ||
| assert rv.status_code == 201 | ||
|
|
||
| model = db.session.query(SavedQuery).get(data.get("id")) | ||
| assert model.label == "label1" | ||
|
|
||
| # Rollback changes | ||
| db.session.delete(model) | ||
| db.session.commit() | ||
|
|
||
| @pytest.mark.usefixtures("create_saved_queries") | ||
| def test_update_saved_query_blank_label(self) -> None: | ||
| """ | ||
| Saved Query API: Test update rejects blank/whitespace-only labels | ||
| """ | ||
| saved_query = ( | ||
| db.session.query(SavedQuery).filter(SavedQuery.label == "label1").all()[0] | ||
| ) | ||
|
Comment on lines
+732
to
+734
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. Suggestion: Add an explicit type annotation for this ORM model variable to comply with the rule requiring type hints on relevant variables in new code. [custom_rule] Severity Level: Minor Why it matters? 🤔The new local ORM result variable is unannotated, and it is a relevant variable that can be type-hinted under the stated rule. (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** tests/integration_tests/queries/saved_queries/api_tests.py
**Line:** 732:734
**Comment:**
*Custom Rule: Add an explicit type annotation for this ORM model variable to comply with the rule requiring type hints on relevant variables in new code.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| self.login(ADMIN_USERNAME) | ||
| uri = f"api/v1/saved_query/{saved_query.id}" | ||
|
|
||
| rv = self.client.put(uri, json={"label": " "}) | ||
| data = json.loads(rv.data.decode("utf-8")) | ||
| assert rv.status_code == 422 | ||
| assert "label" in data["message"] | ||
|
|
||
| @pytest.mark.usefixtures("create_saved_queries") | ||
| def test_update_saved_query(self): | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| import pytest | ||
| from marshmallow import ValidationError | ||
|
|
||
| from superset.queries.saved_queries.schemas import validate_label | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", ["", " ", "\t\n", None]) | ||
| def test_validate_label_rejects_blank(value: str | None) -> None: | ||
| with pytest.raises(ValidationError): | ||
| validate_label(value) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", ["my query", " padded "]) | ||
| def test_validate_label_accepts_non_blank(value: str) -> None: | ||
| # Should not raise for labels containing non-whitespace characters. | ||
| validate_label(value) |
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.
Suggestion: Add an explicit type annotation to this newly introduced class-level variable to comply with the requirement for annotating relevant variables. [custom_rule]
Severity Level: Minor⚠️
Why it matters? 🤔
This is newly added Python code and the class-level variable is unannotated. The rule requires type hints for relevant variables that can be annotated, so this is a real violation.
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖