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


##########
tests/integration_tests/conftest.py:
##########
@@ -407,11 +409,12 @@ def physical_dataset():
 
     yield dataset
 
-    engine.execute(
-        text("""
-        DROP TABLE physical_dataset;
-        """)
-    )
+    with engine.begin() as conn:
+        conn.execute(
+            text("""
+            DROP TABLE physical_dataset;
+            """)
+        )

Review Comment:
   **Suggestion:** The teardown block reuses `engine` after leaving `with 
example_database.get_sqla_engine() as engine:`. That context manager is 
responsible for connection lifecycle (including SSH tunnel cleanup), so using 
the same engine later can fail with closed/disposed resources. Open a fresh 
`get_sqla_engine()` context inside teardown before executing the drop 
statement. [stale reference]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ physical_dataset teardown may fail on SSH-tunneled example_database.
   - ⚠️ Flaky failures in test_time_column_with_time_grain integration test.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Run pytest for `test_time_column_with_time_grain` in
   `tests/integration_tests/query_context_tests.py:1086`, which requests the
   `physical_dataset` fixture defined in 
`tests/integration_tests/conftest.py:351-418` (PR
   diff).
   
   2. During fixture setup, `physical_dataset` calls `get_example_database()` 
and enters
   `with example_database.get_sqla_engine() as engine:` at
   `tests/integration_tests/conftest.py:357`. Inside this block, the table is 
created and
   populated via `engine.begin()` while `Database.get_sqla_engine()`
   (`superset/models/core.py:456-590`) manages SSH tunnels, engine context, and 
OAuth2.
   
   3. After inserts, the `with example_database.get_sqla_engine() as engine:` 
context exits
   before `yield dataset` at `tests/integration_tests/conftest.py:71-91`, 
unwinding
   `Database.get_sqla_engine`’s internals: SSH tunnel context
   (`superset/models/core.py:23-32`), engine context manager, and in some 
configurations
   disposal of the private engine (`superset/models/core.py:25-37`).
   
   4. Once the test function finishes and fixture teardown runs, code at
   `tests/integration_tests/conftest.py:412-417` executes `with engine.begin() 
as conn:`
   using the same `engine` object outside its managing context. If 
`example_database` is
   configured with an SSH tunnel or prequeries, this teardown call tries to 
open a new
   connection on a disposed engine and/or closed tunnel, leading to connection 
errors during
   `DROP TABLE physical_dataset` and causing flaky failures in any tests that 
depend on
   `physical_dataset`.
   ```
   </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=291e6e55a4e84422805041aedaa2ca39&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=291e6e55a4e84422805041aedaa2ca39&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/conftest.py
   **Line:** 412:417
   **Comment:**
        *Stale Reference: The teardown block reuses `engine` after leaving 
`with example_database.get_sqla_engine() as engine:`. That context manager is 
responsible for connection lifecycle (including SSH tunnel cleanup), so using 
the same engine later can fail with closed/disposed resources. Open a fresh 
`get_sqla_engine()` context inside teardown before executing the drop statement.
   
   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%2F41917&comment_hash=ed3029d95b4ae58f2ec57cfe843f98ff9e4145d04815f28550c1bc00368f33a8&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41917&comment_hash=ed3029d95b4ae58f2ec57cfe843f98ff9e4145d04815f28550c1bc00368f33a8&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