Skip to content

AAP-56032 Do not run feature flag logic for partial migrations#918

Open
AlanCoding wants to merge 2 commits intoansible:develfrom
AlanCoding:early_purge
Open

AAP-56032 Do not run feature flag logic for partial migrations#918
AlanCoding wants to merge 2 commits intoansible:develfrom
AlanCoding:early_purge

Conversation

@AlanCoding
Copy link
Copy Markdown
Member

@AlanCoding AlanCoding commented Jan 16, 2026

Description

Trying to test #916, I couldn't do this:

python manage.py migrate dab_rbac 0001

for

  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/core/management/commands/migrate.py", line 380, in handle
    emit_post_migrate_signal(
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/core/management/sql.py", line 52, in emit_post_migrate_signal
    models.signals.post_migrate.send(
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/repos/django-ansible-base/ansible_base/feature_flags/utils.py", line 34, in create_initial_data
    load_feature_flags()
  File "/home/arominge/repos/django-ansible-base/ansible_base/feature_flags/utils.py", line 64, in load_feature_flags
    if existing_flag:
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/models/query.py", line 400, in __bool__
    self._fetch_all()
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/models/query.py", line 1954, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/models/query.py", line 93, in __iter__
    results = compiler.execute_sql(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/models/sql/compiler.py", line 1623, in execute_sql
    cursor.execute(sql, params)
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/venvs/awx/lib64/python3.11/site-packages/psycopg/cursor.py", line 97, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: relation "dab_feature_flags_aapflag" does not exist
LINE 1: ...t_url", "dab_feature_flags_aapflag"."labels" FROM "dab_featu...

Because the feature flags failed on non-existing table, which is bad practice.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test update
  • Refactoring (no functional changes)
  • Development environment change
  • Configuration change

Self-Review Checklist

  • I have performed a self-review of my code
  • I have added relevant comments to complex code sections
  • I have updated documentation where needed
  • I have considered the security impact of these changes
  • I have considered performance implications
  • I have thought about error handling and edge cases
  • I have tested the changes in my local environment

Note

Prevents feature-flag DB operations during partial migrations.

  • Add migrations_are_complete() guard in load_feature_flags() and purge_feature_flags() to early-return with a debug log
  • Avoids querying dab_feature_flags.AAPFlag when schema/tables aren’t ready during partial/incomplete migrations

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

@github-actions
Copy link
Copy Markdown

DVCS PR Check Results:

PR appears valid (JIRA key(s) found)

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 New issue
45.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@zkayyali812 zkayyali812 mentioned this pull request Feb 13, 2026
13 tasks
zkayyali812 added a commit that referenced this pull request Feb 13, 2026
## Description

Alternativate fix to - #918, with more concise check and corrected log
message

- What is being changed?
Adds logic to block feature flags loading code from running during
partial migrations
- Why is this change needed?
This change is needed to ensure restore flow works reliably
- How does this change address the issue?
This change addresses the issue by adding a guard to ensure that the
feature flags load logic does not run when migrations are incomplete

## Type of Change
<!-- Mandatory: Check one or more boxes that apply -->
- [x] Bug fix (non-breaking change which fixes an issue)

## Self-Review Checklist
<!-- These items help ensure quality - they complement our automated CI
checks -->
- [ ] I have performed a self-review of my code
- [ ] I have added relevant comments to complex code sections
- [ ] I have updated documentation where needed
- [ ] I have considered the security impact of these changes
- [ ] I have considered performance implications
- [ ] I have thought about error handling and edge cases
- [ ] I have tested the changes in my local environment

## Testing Instructions
<!-- Optional for test-only changes. Mandatory for all other changes -->
<!-- Must be detailed enough for reviewers to reproduce -->
### Prerequisites
<!-- List any specific setup required -->

### Steps to Test
1. 
2. 
3. 

### Expected Results
<!-- Describe what should happen after following the steps -->

## Additional Context
<!-- Optional but helpful information -->

### Required Actions
<!-- Check if changes require work in other areas -->
<!-- Remove section if no external actions needed -->
- [ ] Requires documentation updates
  <!-- API docs, feature docs, deployment guides -->
- [ ] Requires downstream repository changes
  <!-- Specify repos: django-ansible-base, eda-server, etc. -->
- [ ] Requires infrastructure/deployment changes
  <!-- CI/CD, installer updates, new services -->
- [ ] Requires coordination with other teams
  <!-- UI team, platform services, infrastructure -->
- [ ] Blocked by PR/MR: #XXX
  <!-- Reference blocking PRs/MRs with brief context -->

### Screenshots/Logs
<!-- Add if relevant to demonstrate the changes -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved database migration reliability by adding a safety check that
defers feature flag initialization until all pending migrations are
complete, reducing potential errors during migration processes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
huffmanca pushed a commit to huffmanca/django-ansible-base that referenced this pull request Apr 13, 2026
## Description

Alternativate fix to - ansible#918, with more concise check and corrected log
message

- What is being changed?
Adds logic to block feature flags loading code from running during
partial migrations
- Why is this change needed?
This change is needed to ensure restore flow works reliably
- How does this change address the issue?
This change addresses the issue by adding a guard to ensure that the
feature flags load logic does not run when migrations are incomplete

## Type of Change
<!-- Mandatory: Check one or more boxes that apply -->
- [x] Bug fix (non-breaking change which fixes an issue)

## Self-Review Checklist
<!-- These items help ensure quality - they complement our automated CI
checks -->
- [ ] I have performed a self-review of my code
- [ ] I have added relevant comments to complex code sections
- [ ] I have updated documentation where needed
- [ ] I have considered the security impact of these changes
- [ ] I have considered performance implications
- [ ] I have thought about error handling and edge cases
- [ ] I have tested the changes in my local environment

## Testing Instructions
<!-- Optional for test-only changes. Mandatory for all other changes -->
<!-- Must be detailed enough for reviewers to reproduce -->
### Prerequisites
<!-- List any specific setup required -->

### Steps to Test
1. 
2. 
3. 

### Expected Results
<!-- Describe what should happen after following the steps -->

## Additional Context
<!-- Optional but helpful information -->

### Required Actions
<!-- Check if changes require work in other areas -->
<!-- Remove section if no external actions needed -->
- [ ] Requires documentation updates
  <!-- API docs, feature docs, deployment guides -->
- [ ] Requires downstream repository changes
  <!-- Specify repos: django-ansible-base, eda-server, etc. -->
- [ ] Requires infrastructure/deployment changes
  <!-- CI/CD, installer updates, new services -->
- [ ] Requires coordination with other teams
  <!-- UI team, platform services, infrastructure -->
- [ ] Blocked by PR/MR: #XXX
  <!-- Reference blocking PRs/MRs with brief context -->

### Screenshots/Logs
<!-- Add if relevant to demonstrate the changes -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved database migration reliability by adding a safety check that
defers feature flag initialization until all pending migrations are
complete, reducing potential errors during migration processes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@AlanCoding AlanCoding requested a review from zkayyali812 April 15, 2026 13:59
@zkayyali812
Copy link
Copy Markdown
Contributor

Hey @AlanCoding I think this PR can be closed now. This fix was already resolved here - #942

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants