Skip to content

Conversation

@chrismeyersfsu
Copy link
Member

@chrismeyersfsu chrismeyersfsu commented Feb 9, 2026

  • Multiple credentialtype's have the same kind and kind values look like: cloud, network, machine, etc.
  • namespace is the field that we want to rename

Jira: https://issues.redhat.com/browse/AAP-64432

SUMMARY
ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • API
ADDITIONAL INFORMATION


Note

Low Risk
Migration-only changes with a targeted data update and added tests; risk is limited to upgrade paths where CredentialType.namespace values are rewritten.

Overview
Fixes the GitHub App credential-type migration in 0204_squashed_deletions to update CredentialType.namespace from github_app to github_app_lookup (instead of incorrectly updating kind).

Makes several RunPython migrations explicitly reversible in tests by adding migrations.RunPython.noop reverse functions (in 0201_create_managed_creds, 0202_convert_controller_role_definitions, and the GitHub App update step). Adds a functional migration regression test that creates a legacy namespace='github_app' record, applies 0204, and asserts the value is rewritten to prevent the createsuperuser KeyError.

Written by Cursor Bugbot for commit 7799104. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed credential-type mapping for GitHub App credentials during upgrades.
  • Chores

    • Improved database migration handling to ensure cleaner, more reliable upgrade paths.
  • Tests

    • Added functional test coverage for credential-type migrations and post-migration superuser creation.

@chrismeyersfsu
Copy link
Member Author

Tested in my dev env manually:

  1. Rollback migrations
awx-manage migrate main 0203_remove_team_of_team
  1. edit 0204_squashed_deletions.py
    Change the migration to some credential in your dev env to test the rename. I didn't have the github app in mine so I used the github token.
CredentialType.objects.using(db_alias).filter(namespace='github_token').update(namespace='github_token_lookup')
  1. Re-run the migration
awx-manage migrate
  1. Verify
awx-manage shell_plus
CredentialType.objects.filter(namespace='github_token_lookup').count()   <--- should be 1

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Adds no-op reverse callables to two RunPython migrations, fixes a CredentialType migration to use namespace instead of kind, and adds a functional test that validates the github app namespace migration and post-migration behavior.

Changes

Cohort / File(s) Summary
Irreversible Migration Operations
awx/main/migrations/0201_create_managed_creds.py, awx/main/migrations/0202_convert_controller_role_definitions.py
RunPython calls now include migrations.RunPython.noop as the reverse callable, making those migration steps explicitly no-op on reverse.
CredentialType Namespace Migration
awx/main/migrations/0204_squashed_deletions.py
Changed migration update/filter to operate on the namespace field (e.g., namespace='github_app'namespace='github_app_lookup') instead of the kind field.
Migration Test Addition
awx/main/tests/functional/test_migrations.py
Added TestGithubAppBug with test_after_github_app_kind_migration to exercise migrations up to 0203, create a historical CredentialType with old values, apply 0204, and assert namespace was migrated and awx-manage createsuperuser runs without KeyError.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main fix: correcting a field rename for GitHub App from kind to namespace in migration 0204.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@awx/main/tests/functional/test_migrations.py`:
- Around line 186-191: Update the stale comments and docstring in the
test_after_github_app_kind_migration test to reference the correct migration
name and field: change all occurrences of "0202_squashed_deletions" to
"0204_squashed_deletions" and replace references to the updated field "kind"
with "namespace" (or similar wording reflecting the actual change). Ensure any
inline comments elsewhere in the same test file that mention the migration
number or the field update (including comments around assertions and setup in
test_migrations.py) are adjusted so they accurately describe that
update_github_app_kind changed the namespace field after the
0204_squashed_deletions migration.
- Around line 217-220: The assertion is vacuous because the test created
CredentialType(kind='external'), so checking that no CredentialType with
kind='github_app' exists is meaningless; update the assertion to verify that no
CredentialType with namespace='github_app' exists after the migration (e.g.
replace the filter kind='github_app' with namespace='github_app' against
CredentialType.objects.exists()) so the test asserts the migration removed the
namespace value as intended (refer to the CredentialType model and the test
function in test_migrations.py).
🧹 Nitpick comments (1)
awx/main/migrations/0204_squashed_deletions.py (1)

7-15: Stale docstring — still references kind field.

The docstring says "Updates the 'kind' field" but the code now updates namespace. The function name update_github_app_kind is similarly misleading. Consider updating at least the docstring to reflect the actual change. Renaming the function is fine too since it's only referenced within this migration file (Line 122).

Suggested docstring fix
 def update_github_app_kind(apps, schema_editor):
     """
-    Updates the 'kind' field for CredentialType records
-    from 'github_app' to 'github_app_lookup'.
-    This addresses a change in the entry point key for the GitHub App plugin.
+    Updates the 'namespace' field for CredentialType records
+    from 'github_app' to 'github_app_lookup'.
+    This addresses a change in the entry point key for the GitHub App plugin.
     """

@AlanCoding AlanCoding requested a review from djyasin February 11, 2026 17:38
@chrismeyersfsu chrismeyersfsu enabled auto-merge (rebase) February 12, 2026 00:58
@chrismeyersfsu chrismeyersfsu force-pushed the AAP-64432-github_app_fix branch from c9d69bd to 7ec0705 Compare February 12, 2026 12:30
@ansible ansible deleted a comment from coderabbitai bot Feb 12, 2026
@chrismeyersfsu
Copy link
Member Author

@coderabbitai review

* Multiple credentialtype's have the same kind and kind values look
  like: cloud, network, machine, etc.
* namespace is the field that we want to rename
@chrismeyersfsu chrismeyersfsu force-pushed the AAP-64432-github_app_fix branch from 7ec0705 to 825f5d0 Compare February 12, 2026 13:55
* Introduced in PR https://github.com/ansible/awx/pull/16058/changes
  then a later large merge from AAP back into devel removed the changes
* This PR re-introduces the github app lookup migration rename tests
  with the migration names updated and the kind to namespace correction
@chrismeyersfsu chrismeyersfsu force-pushed the AAP-64432-github_app_fix branch from 825f5d0 to 7799104 Compare February 12, 2026 13:58
@sonarqubecloud
Copy link

Copy link
Member

@fosterseth fosterseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrismeyersfsu chrismeyersfsu merged commit 01293f1 into ansible:devel Feb 12, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants