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


##########
tests/unit_tests/databases/schema_tests.py:
##########
@@ -557,6 +557,41 @@ def test_extra_validator_accepts_catalog_cache_timeout() 
-> None:
     assert extra["metadata_cache_timeout"]["catalog_cache_timeout"] == 600
 
 
+def test_extra_validator_interpolates_invalid_metadata_params_key() -> None:
+    """
+    The message names the offending key. It is built with a lazy translated
+    string, so a malformed placeholder would only fail once the message is
+    rendered; asserting on the rendered text pins the interpolation.
+    """
+    from superset.databases.schemas import DatabasePostSchema
+
+    schema = DatabasePostSchema()
+    payload = {
+        "database_name": "test_db",
+        "extra": json.dumps({"metadata_params": {"not_a_metadata_arg": 1}}),
+    }
+    with pytest.raises(ValidationError) as exc_info:
+        schema.load(payload)
+    message = str(exc_info.value)
+    assert "not_a_metadata_arg" in message
+    assert "%(" not in message
+
+
+def test_extra_validator_interpolates_json_decode_error() -> None:
+    """
+    As above, for the message raised when ``extra`` is not decodable JSON.
+    """
+    from superset.databases.schemas import DatabasePostSchema
+
+    schema = DatabasePostSchema()
+    payload = {"database_name": "test_db", "extra": "{not json"}
+    with pytest.raises(ValidationError) as exc_info:
+        schema.load(payload)
+    message = str(exc_info.value)
+    assert "Field cannot be decoded by JSON" in message

Review Comment:
   **Suggestion:** The assertion depends on the English translation returned by 
`lazy_gettext`; when the test suite renders messages under a non-English 
locale, the valid translated message will not contain this English prefix and 
the test will fail even though interpolation works. Assert the 
interpolation-specific content or explicitly force the locale for this test. 
[possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Database schema tests can fail under non-English locales.
   - ⚠️ Valid translated validation responses are incorrectly rejected by tests.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Execute `test_extra_validator_interpolates_json_decode_error()` at
   `tests/unit_tests/databases/schema_tests.py:580` in a test process 
configured with a
   non-English Flask-Babel locale.
   
   2. The test calls `DatabasePostSchema.load()` at
   `tests/unit_tests/databases/schema_tests.py:589`, which uses 
`extra_validator()` at
   `superset/databases/schemas.py:258`.
   
   3. For malformed JSON, `extra_validator()` constructs the lazy translated 
message at
   `superset/databases/schemas.py:268`; rendering `str(exc_info.value)` at
   `tests/unit_tests/databases/schema_tests.py:590` produces the active 
locale's translation.
   
   4. The assertion at `tests/unit_tests/databases/schema_tests.py:591` 
requires the English
   text `Field cannot be decoded by JSON`, so a valid translated message can 
fail the test
   despite correct interpolation. Assert only stable interpolation-specific 
content or
   explicitly force the English locale.
   ```
   </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=9f6d516fe6914b1cb07d97c80313c8d9&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=9f6d516fe6914b1cb07d97c80313c8d9&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/unit_tests/databases/schema_tests.py
   **Line:** 591:591
   **Comment:**
        *Possible Bug: The assertion depends on the English translation 
returned by `lazy_gettext`; when the test suite renders messages under a 
non-English locale, the valid translated message will not contain this English 
prefix and the test will fail even though interpolation works. Assert the 
interpolation-specific content or explicitly force the locale for this test.
   
   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%2F42411&comment_hash=145a23ef803fb1ac9a6a6f3b6f1642d1cf3a85ec24ac584ec9b87475d28b1eb1&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42411&comment_hash=145a23ef803fb1ac9a6a6f3b6f1642d1cf3a85ec24ac584ec9b87475d28b1eb1&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