Repository navigation
Check all names before airflow roles import writes anything - #74711
Merged
Merged
Conversation
vincbeck
approved these changes
Oct 14, 2026
28 of 93 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
airflow roles importwrites each entry as it goes, and every role and permission is committed on its own. When an entry names a resource or action that the target database does not have (a plugin view, a newer or older provider, a hand-edited file), the command stops at that entry with exit code 1. The roles and permissions written before it stay in the database.The re-run after the user fixes the file makes this worse.
roles_importskips every role name that already exists, so the half-imported role is skipped. The command prints "roles and permissions successfully imported" and exits 0, and that role is still missing permissions.Repro on main (fresh SQLite DB,
db migrateandsync-perm, then the import). The file givesTeamVieweraccess to DAG Runs, a plugin viewData Quality Dashboardand Task Instances, and givesTeamOpsaccess to Pools:An unknown action (
"action": "can_read,can_rerun") gives the same result.Change
Before the first write,
roles_importnow checks the resource and action names of every entry it is going to import against the database. These are the sameget_resource/get_actionlookups that the add-permissions step already does for each entry. If any name is unknown, the command prints each unknown name once, prints "No roles were imported" and exits 1 before it writes any role or permission from the file. If all names are known, the import runs as before.With the change, the same two runs:
What does not change:
add-permsanddel-permsare not changed.This follows the approach that
[fab] custom_roles(#72820) takes for the same reason: validate everything before creating any role, so that a failure does not leave a role that a later run skips.Testing
test_cli_import_roles_with_unknown_names_changes_nothing: unknown resource, unknown action, and several unknown names repeated across entries. Each case asserts exit code 1, each unknown name printed exactly once, and no role created. All three fail on main and pass with the change. A new testtest_cli_import_roles_skips_entries_of_existing_roles_before_checking_namescovers the unchanged skip rule. It passes on main and with the change.pytest providers/fab/tests/unit/fab/auth_manager/cli_commands/test_role_command.pyon SQLite with Python 3.11: 13 passed with the change, and 9 passed for main's version of the file on main.Poolsexit with "Resource named 'Pools' does not exist" (main and this branch alike), because the FAB resources do not exist until permissions are synced. The results above used a DB whereairflow sync-permhad run after the test DB init.prek run --fileson both files: passed.mypyonrole_command.py: no issues. I could not run the manualmypy-providershook because breeze is not installed, and I did not test on PostgreSQL or MySQL.No changelog entry, because the change is not breaking.
related: #72796, #72820
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5.5) following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.