codeant-ai-for-open-source[bot] commented on code in PR #42917:
URL: https://github.com/apache/superset/pull/42917#discussion_r3741099208


##########
tests/integration_tests/sql_lab/api_tests.py:
##########
@@ -336,6 +336,29 @@ def test_format_sql_request_with_jinja(self):
         assert "{{tbl}}" not in resp_data["result"]
         assert resp_data["result"] == expected
 
+    def test_format_sql_request_with_undefined_jinja_attribute(self):
+        self.login(ADMIN_USERNAME)
+        example_db = get_example_database()
+
+        # Attribute access on an undefined Jinja variable (``tbl`` is not in 
the
+        # template params) raises a jinja2 ``UndefinedError`` from within
+        # ``process_template``. This should surface as a typed 400, not an 
opaque
+        # 500 from the global exception handler. A non-empty 
``template_params``
+        # dict is required so the endpoint actually invokes 
``process_template``.
+        data = {
+            "sql": "select * from {{ tbl.name }}",
+            "database_id": example_db.id,
+            "template_params": json.dumps({"unrelated": "value"}),
+        }
+        rv = self.client.post(
+            "/api/v1/sqllab/format_sql/",
+            json=data,
+        )
+        resp_data = json.loads(rv.data.decode("utf-8"))
+        assert rv.status_code == 400
+        assert "tbl" in resp_data["errors"][0]["message"]
+        assert "undefined" in resp_data["errors"][0]["message"]

Review Comment:
   **Suggestion:** The regression test does not verify the required typed error 
contract. A different 400 response, such as a generic validation error 
containing the same message fragments, would pass these assertions even if 
`error_type` were no longer `GENERIC_COMMAND_ERROR`; assert the returned error 
type (and, if part of the contract, its level) explicitly. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Minor ๐Ÿงน</summary>
   
   ```mdx
   - โš ๏ธ Future error-type regressions can pass CI unnoticed.
   - โš ๏ธ SQL Lab clients may receive an incorrect typed error contract.
   - โš ๏ธ Current API handler explicitly promises GENERIC_COMMAND_ERROR responses.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=91434d1c4598479eb3bf04e2652f17fd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=91434d1c4598479eb3bf04e2652f17fd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/integration_tests/sql_lab/api_tests.py
   **Line:** 358:360
   **Comment:**
        *Api Mismatch: The regression test does not verify the required typed 
error contract. A different 400 response, such as a generic validation error 
containing the same message fragments, would pass these assertions even if 
`error_type` were no longer `GENERIC_COMMAND_ERROR`; assert the returned error 
type (and, if part of the contract, its level) explicitly.
   
   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
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42917&comment_hash=05ce142ee23affe5ec04f706a33dfe3cd67d96b4fe747b173ce5096322f9ea64&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42917&comment_hash=05ce142ee23affe5ec04f706a33dfe3cd67d96b4fe747b173ce5096322f9ea64&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to