You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "windro-xdd (via GitHub)" <gi...@apache.org> on 2026/04/18 11:21:56 UTC

[PR] FAB: fix FK-safe role deletion in security manager [airflow]

windro-xdd opened a new pull request, #65464:
URL: https://github.com/apache/airflow/pull/65464

   This fixes role deletion in the FAB security manager used by the API role delete flow.
   
   When deleting a role, we now remove related rows from role association tables first (permission-role, user-role, group-role) and then delete the role row. This avoids FK violations in environments where relying on DB-level cascade behavior is not sufficient.
   
   Also adds regression tests for:
   - cleanup-before-delete behavior
   - missing-role path (raises and does not execute/commit)
   
   related: #65375
   
   What I tested:
   - breeze run --skip-image-upgrade-check pytest providers/fab/tests/unit/fab/auth_manager/security_manager/test_override.py -xvs
   - breeze run --skip-image-upgrade-check pytest providers/fab/tests/unit/fab/auth_manager/api_fastapi/services/test_roles.py providers/fab/tests/unit/fab/auth_manager/api_fastapi/routes/test_roles.py -xvs
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FAB: fix FK-safe role deletion in security manager [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #65464:
URL: https://github.com/apache/airflow/pull/65464#issuecomment-4383011341

   @windro-xdd This draft PR has been inactive for 12 days since the last triage comment and no response from the author. Closing to keep the queue clean.
   
   You are welcome to reopen this PR when you resume work, or to open a new one addressing the issues previously raised. There is no rush — take your time.
   
   ---
   
   _Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this [two-stage triage process](https://github.com/apache/airflow/blob/main/contributing-docs/25_maintainer_pr_triage.md#why-the-first-pass-is-automated) so that our maintainers' limited time is spent where it matters most: the conversation with you._
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FAB: fix FK-safe role deletion in security manager [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #65464:
URL: https://github.com/apache/airflow/pull/65464#issuecomment-4300992315

   @windro-xdd This PR has been converted to **draft** because it does not yet meet our [Pull Request quality criteria](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-quality-criteria).
   
   **Issues found:**
   - :x: **Unresolved review comments** (1 thread (from maintainers)): please walk through each unresolved review thread. **Even if a suggestion looks incorrect or irrelevant** — and some of them will be, especially any comments left by automated reviewers like GitHub Copilot — it is still the author's responsibility to respond: apply the fix, reply in-thread with a brief explanation of why the suggestion does not apply, or resolve the thread if the feedback is no longer relevant. **Once you believe a thread is resolved — whether by pushing a fix or by explaining why the suggestion doesn't apply — please mark it as resolved yourself by clicking the 'Resolve conversation' button at the bottom of each thread.** Reviewers don't auto-close their own threads, so an addressed-but-unresolved thread reads as 'still waiting on the author' and keeps the PR from moving forward.
   
   **What to do next:**
   - Address the items above.
   - Make sure static checks pass locally: `prek run --from-ref main --stage pre-commit`.
   - Mark the PR as "Ready for review" when you are done.
   
   Converting a PR to draft is **not** a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the [Airflow Slack](https://s.apache.org/airflow-slack).


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FAB: fix FK-safe role deletion in security manager [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk closed pull request #65464: FAB: fix FK-safe role deletion in security manager
URL: https://github.com/apache/airflow/pull/65464


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FAB: fix FK-safe role deletion in security manager [airflow]

Posted by "vincbeck (via GitHub)" <gi...@apache.org>.
vincbeck commented on code in PR #65464:
URL: https://github.com/apache/airflow/pull/65464#discussion_r3111516525


##########
providers/fab/tests/unit/fab/auth_manager/security_manager/test_override.py:
##########
@@ -43,6 +49,62 @@ def __init__(self):
 
 
 class TestFabAirflowSecurityManagerOverride:
+    def test_delete_role_cleans_associations_before_delete(self):
+        sm = EmptySecurityManager()
+        role = Mock(spec=Role)
+        role.id = 42
+        role.name = "roleA"
+        mock_session = Mock(spec=Session)
+
+        mock_scalars = Mock()
+        mock_scalars.first.return_value = role
+        mock_session.scalars.return_value = mock_scalars
+
+        with mock.patch.object(EmptySecurityManager, "session", mock_session):
+            sm.delete_role("roleA")
+
+        executed_statements = [call_args.args[0] for call_args in mock_session.execute.call_args_list]
+        assert len(executed_statements) == 4
+
+        first = str(executed_statements[0].compile(compile_kwargs={"literal_binds": True}))
+        second = str(executed_statements[1].compile(compile_kwargs={"literal_binds": True}))
+        third = str(executed_statements[2].compile(compile_kwargs={"literal_binds": True}))
+        fourth = str(executed_statements[3].compile(compile_kwargs={"literal_binds": True}))
+
+        assert f"DELETE FROM {assoc_permission_role.name}" in first
+        assert "WHERE" in first
+        assert "role_id" in first
+        assert "42" in first
+        assert f"DELETE FROM {assoc_user_role.name}" in second
+        assert "WHERE" in second
+        assert "role_id" in second
+        assert "42" in second
+        assert f"DELETE FROM {assoc_group_role.name}" in third
+        assert "WHERE" in third
+        assert "role_id" in third
+        assert "42" in third
+        assert "DELETE FROM ab_role" in fourth
+        assert "WHERE" in fourth
+        assert "id" in fourth
+        assert "42" in fourth

Review Comment:
   This looks really wrong



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org