bito-code-review[bot] commented on code in PR #41974:
URL: https://github.com/apache/superset/pull/41974#discussion_r3566361081


##########
tests/unit_tests/commands/importers/v1/utils_test.py:
##########
@@ -117,3 +124,62 @@ def test_warning_count_excludes_preexisting_nulls(self) -> 
None:
 
         call_args = mock_logger.warning.call_args[0]
         assert call_args[1] == 2  # 2 out-of-bounds, 1 pre-existing null
+
+
+class TestLoadConfigs:
+    def test_load_configs_caught_exception_and_log_redacted_configs(self) -> 
None:
+        logging.basicConfig(level=logging.DEBUG)
+        from superset.commands.importers.v1.utils import (
+            load_configs,
+        )
+
+        with (
+            patch("superset.db") as mock_db,
+            patch("yaml.safe_load") as mock_yaml_safe_load,
+            patch("superset.commands.importers.v1.utils.logger") as 
mock_logger,
+        ):
+            mock_yaml_safe_load.return_value = {
+                "masked_encrypted_extra": json.dumps(
+                    {"oauth2_client_info": {"secret": "MASKED"}}
+                ),
+                "ssh_tunnel": {},
+            }
+            mock_db.session.query.return_value = {"uuid-1": 
"SECRET_TO_BE_SEEN"}

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Incorrect mock causes AttributeError</b></div>
   <div id="fix">
   
   Mock at line 147 sets `return_value` to a dict, but production code calls 
`.all()` on this result (`utils.py:123`). SQLAlchemy's `.all()` returns a list 
of tuples, not a dict. Fix: use 
`mock_db.session.query.return_value.all.return_value = [("uuid-1", 
"SECRET_TO_BE_SEEN")]`. This test would pass in isolation only if the exception 
is caught before reaching the query code path, masking the real bug.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
           mock_db.session.query.return_value = {"uuid-1": "SECRET_TO_BE_SEEN"}
           mock_db.session.query.return_value.all.return_value = [("uuid-1", 
"SECRET_TO_BE_SEEN")]
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #a65b05</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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