codeant-ai-for-open-source[bot] commented on code in PR #38584:
URL: https://github.com/apache/superset/pull/38584#discussion_r3633563142
##########
tests/integration_tests/charts/commands_tests.py:
##########
@@ -669,6 +716,45 @@ def test_update_chart_dashboard_security_admin_bypass(
db.session.delete(alpha_dashboard)
db.session.commit()
+ @patch("superset.commands.chart.update.g")
+ @patch("superset.utils.core.g")
+ @patch("superset.security.manager.g")
+ @pytest.mark.usefixtures("load_energy_table_with_slice")
+ def test_update_chart_rejects_new_externally_managed_dashboard(
+ self, mock_sm_g, mock_u_g, mock_c_g
+ ):
+ """Test that updating a chart to add an externally managed dashboard
fails"""
+ from superset.models.dashboard import Dashboard
+
+ admin = security_manager.find_user(username="admin")
+ mock_u_g.user = mock_c_g.user = mock_sm_g.user = admin
+
+ chart = db.session.query(Slice).first()
+ chart.owners = [admin]
Review Comment:
**Suggestion:** The test mutates a shared persisted chart by reassigning
owners and never restores the original ownership, which can alter
permissions/state assumptions for later tests that reuse seeded chart records.
[logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Shared Slice owners permanently changed by this test.
- ⚠️ Later tests using first Slice see modified ownership.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Run the backend pytest suite including
`tests/integration_tests/charts/commands_tests.py`.
2. In `test_update_chart_rejects_new_externally_managed_dashboard` (lines
723-757), the
test retrieves a shared chart fixture via `chart =
db.session.query(Slice).first()` at
line 732.
3. Immediately after, `chart.owners = [admin]` at line 733 mutates the ORM
object without
any corresponding restoration of the previous owners later in the test.
4. When `db.session.commit()` is called for the `managed_dashboard` at line
745,
SQLAlchemy flushes all pending changes, persisting the new `chart.owners`
assignment; the
subsequent cleanup at lines 755-756 deletes only `managed_dashboard`,
leaving the modified
`Slice` owners in the database for any later tests that query the first
`Slice`, causing
permanent cross-test state changes.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2069e9ea462447aea56675a7fc75611f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2069e9ea462447aea56675a7fc75611f&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/charts/commands_tests.py
**Line:** 732:733
**Comment:**
*Logic Error: The test mutates a shared persisted chart by reassigning
owners and never restores the original ownership, which can alter
permissions/state assumptions for later tests that reuse seeded chart records.
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%2F38584&comment_hash=e6eb8199d46a3f153f8af1756180ac1fff2594065e752fb268a16d9f0c30c1e6&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38584&comment_hash=e6eb8199d46a3f153f8af1756180ac1fff2594065e752fb268a16d9f0c30c1e6&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]