Skip to content

Comments

Address more ignored pytest warnings, co-authored with Opus 4.6#16298

Open
AlanCoding wants to merge 3 commits intoansible:develfrom
AlanCoding:claude_test_warnings2
Open

Address more ignored pytest warnings, co-authored with Opus 4.6#16298
AlanCoding wants to merge 3 commits intoansible:develfrom
AlanCoding:claude_test_warnings2

Conversation

@AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Feb 20, 2026

SUMMARY

Same as #16269

But fed the same prompt to it again. Addressing low-hanging fruit.

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

Note

Low Risk
Model Meta.ordering changes and test warning filter tweaks are low-impact; primary risk is subtle changes in default API/list ordering where callers relied on implicit DB ordering.

Overview
Ensures deterministic queryset ordering by default by setting ordering = ('pk',) for InstanceGroup, WorkflowJobNode, and WorkflowJobTemplateNode (plus a new Django migration to apply the model option changes).

Cleans up pytest.ini warning filters by removing no-longer-needed suppressions and adding a targeted ignore for UnorderedObjectListWarning emitted by unordered Resource pagination.

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

Summary by CodeRabbit

  • Chores

    • Ensure deterministic ordering for workflow-related records and instance groups so listings are consistently returned by ID unless overridden.
    • Add a new permission to control using instance groups in resource preferences.
  • Tests

    • Consolidated test warning filters and expanded JUnit reporting configuration, changing which test warnings are shown or suppressed.

@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Added default primary-key ordering to three Django model Meta classes (InstanceGroup, WorkflowJobNode, WorkflowJobTemplateNode), added a migration to apply those options, and simplified pytest.ini by removing multiple specific filterwarnings and updating JUnit reporting settings.

Changes

Cohort / File(s) Summary
Workflow model ordering
awx/main/models/workflow.py
Added ordering = ('pk',) to WorkflowJobTemplateNode.Meta and WorkflowJobNode.Meta to make querysets default to primary-key order.
HA model ordering
awx/main/models/ha.py
Added ordering = ('pk',) to InstanceGroup.Meta to set default PK ordering.
Migration
awx/main/migrations/0205_add_ordering_to_instancegroup_and_workflow_nodes.py
New migration altering model options: sets ordering = ('pk',) for instancegroup, workflowjobnode, and workflowjobtemplatenode; adds default_permissions and a use_instancegroup permission for instancegroup.
Test configuration
pytest.ini
Removed multiple specific filterwarnings entries and consolidated warnings; added/updated JUnit reporting configuration (junit_family, junit_logging, junit_log_passing_tests, junit_suite_name).

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 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: addressing ignored pytest warnings by adding model ordering and updating pytest.ini filters.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
awx/main/models/workflow.py (1)

197-203: ⚠️ Potential issue | 🟠 Major

A corresponding migration file is required for Meta.ordering changes.

Django's migration framework tracks Meta.ordering via the AlterModelOptions operation. Adding ordering = ('pk',) to both WorkflowJobTemplateNode.Meta (line 203) and WorkflowJobNode.Meta (line 290) requires a migration file. AWX's CI pipeline includes an explicit api-migrations test job that runs all migrations and will fail if unapplied migrations are detected. A migration file must be generated and committed alongside these model changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@awx/main/models/workflow.py` around lines 197 - 203, The change adds
Meta.ordering = ('pk',) to both WorkflowJobTemplateNode.Meta and
WorkflowJobNode.Meta but no migration was committed; run Django makemigrations
to generate an explicit migration that contains an AlterModelOptions for these
two models (or hand-write an operation that sets ordering if preferred), add and
commit the generated migration file to the repo alongside the model changes so
the api-migrations CI job will apply it.
🧹 Nitpick comments (1)
awx/main/models/workflow.py (1)

203-203: Minor inconsistency: use 'id' to match the existing convention in this file.

WorkflowJob.Meta (line 642) uses ordering = ('id',). Both 'pk' and 'id' resolve identically, but aligning to 'id' keeps the file internally consistent.

♻️ Proposed change
-        ordering = ('pk',)   # WorkflowJobTemplateNode.Meta line 203
+        ordering = ('id',)

-        ordering = ('pk',)   # WorkflowJobNode.Meta line 290
+        ordering = ('id',)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@awx/main/models/workflow.py` at line 203, Change the Meta ordering tuple in
the Workflow model from ('pk',) to ('id',) to match the file-wide convention
(e.g., as used in WorkflowJob.Meta); locate the ordering = ('pk',) line inside
the Workflow.Meta class and replace 'pk' with 'id' so the file consistently uses
'id' for model ordering.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@awx/main/models/workflow.py`:
- Around line 197-203: The change adds Meta.ordering = ('pk',) to both
WorkflowJobTemplateNode.Meta and WorkflowJobNode.Meta but no migration was
committed; run Django makemigrations to generate an explicit migration that
contains an AlterModelOptions for these two models (or hand-write an operation
that sets ordering if preferred), add and commit the generated migration file to
the repo alongside the model changes so the api-migrations CI job will apply it.

---

Nitpick comments:
In `@awx/main/models/workflow.py`:
- Line 203: Change the Meta ordering tuple in the Workflow model from ('pk',) to
('id',) to match the file-wide convention (e.g., as used in WorkflowJob.Meta);
locate the ordering = ('pk',) line inside the Workflow.Meta class and replace
'pk' with 'id' so the file consistently uses 'id' for model ordering.

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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@awx/main/models/ha.py`:
- Around line 486-491: The InstanceGroup.Meta ordering was changed to ordering =
('pk',) but no Django migration was added; create a new migration that uses
migrations.AlterModelOptions to record the ordering change for the InstanceGroup
model (similar to existing migrations like 0077_v360_add_default_orderings.py or
0191_add_django_permissions.py), and if you made a parallel Meta.ordering change
in any workflow-related model (e.g., in workflow.py), include an
AlterModelOptions entry for that model as well; ensure the migration module is
named/numbered consistently, imports the correct app label 'main', and only
alters the model options (no schema changes).

Comment on lines 486 to 491
class Meta:
app_label = 'main'
ordering = ('pk',)
permissions = [('use_instancegroup', 'Can use instance group in a preference list of a resource')]
# Since this has no direct organization field only superuser can add, so remove add permission
default_permissions = ('change', 'delete', 'view')
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for migrations referencing InstanceGroup ordering
rg -n "ordering.*pk" awx/main/migrations/ --type py -l

Repository: ansible/awx

Length of output: 257


🏁 Script executed:

#!/bin/bash
# List all migration files in awx/main/migrations to understand recent changes
ls -la awx/main/migrations/ | tail -20

Repository: ansible/awx

Length of output: 1428


🏁 Script executed:

#!/bin/bash
# Search for InstanceGroup migrations more broadly
rg -n "InstanceGroup" awx/main/migrations/ --type py -l | head -10

Repository: ansible/awx

Length of output: 574


🏁 Script executed:

#!/bin/bash
# Find the highest numbered migration file to see what's most recent
ls -1 awx/main/migrations/*.py | grep -E '0[0-9]{3}_' | sort -V | tail -5

Repository: ansible/awx

Length of output: 316


🏁 Script executed:

#!/bin/bash
# Search all migrations for any mention of ordering on InstanceGroup
rg -n "InstanceGroup" awx/main/migrations/*.py -A 5 -B 5 | grep -A 10 -B 10 "ordering"

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Check git status to see if there are new migration files in this PR
git status --short awx/main/migrations/ 2>/dev/null | head -20

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Check the actual changes to ha.py - is ordering new or already existed?
git diff HEAD awx/main/models/ha.py 2>/dev/null | head -100

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Look at the current InstanceGroup model to confirm ordering is in place
rg -A 10 "class InstanceGroup" awx/main/models/ha.py | head -30

Repository: ansible/awx

Length of output: 562


🏁 Script executed:

#!/bin/bash
# Check if workflow.py also has ordering changes
git diff HEAD awx/main/models/workflow.py 2>/dev/null | head -100

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Read the InstanceGroup Meta class directly from ha.py (lines 480-495)
sed -n '480,495p' awx/main/models/ha.py

Repository: ansible/awx

Length of output: 641


🏁 Script executed:

#!/bin/bash
# Check if there's a recent migration that might include the ordering change
find awx/main/migrations -name "*.py" -type f -exec grep -l "ordering" {} \; | sort

Repository: ansible/awx

Length of output: 803


🏁 Script executed:

#!/bin/bash
# Look for any migration files that might be uncommitted or new in this context
git log --oneline awx/main/migrations/ 2>/dev/null | head -10

Repository: ansible/awx

Length of output: 96


🏁 Script executed:

#!/bin/bash
# Check the content of the ordering migration to see if it includes InstanceGroup
cat awx/main/migrations/0077_v360_add_default_orderings.py

Repository: ansible/awx

Length of output: 1987


🏁 Script executed:

#!/bin/bash
# Also check if workflow.py has ordering in its Meta class
rg -A 8 "class.*Meta:" awx/main/models/workflow.py | grep -A 8 "ordering"

Repository: ansible/awx

Length of output: 657


🏁 Script executed:

#!/bin/bash
# Check if there's a migration that altered InstanceGroup options more recently
rg "InstanceGroup" awx/main/migrations/020*.py -A 3 -B 3

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Verify the commit history to see when ordering was added to InstanceGroup
git log --all --oneline --follow -S "ordering = ('pk',)" -- awx/main/models/ha.py 2>/dev/null | head -5

Repository: ansible/awx

Length of output: 141


🏁 Script executed:

#!/bin/bash
# List all migration files numbered 200 or higher
ls -1 awx/main/migrations/02*.py | sort -V

Repository: ansible/awx

Length of output: 316


🏁 Script executed:

#!/bin/bash
# Check the latest migrations for AlterModelOptions on InstanceGroup
rg "AlterModelOptions" awx/main/migrations/*.py | grep -i instance

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Check if ordering was in the model before (search initial/squashed migrations)
rg "ordering.*=.*pk" awx/main/migrations/0001_initial.py -A 2 -B 2

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Check the squashed migrations for InstanceGroup ordering
rg "InstanceGroup" awx/main/migrations/0002_squashed* awx/main/migrations/0003_squashed* awx/main/migrations/0004_squashed* -A 5 | grep -A 5 "ordering"

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Look at migration 0204 (latest squashed) to see what it covers
head -30 awx/main/migrations/0204_squashed_deletions.py

Repository: ansible/awx

Length of output: 1326


🏁 Script executed:

#!/bin/bash
# Search for when ordering was added to InstanceGroup by checking all migrations
for file in awx/main/migrations/0*.py; do if grep -q "InstanceGroup" "$file" && grep -q "ordering" "$file"; then echo "=== $file ==="; grep -A 10 "InstanceGroup" "$file" | grep -A 3 "ordering"; fi; done

Repository: ansible/awx

Length of output: 103


🏁 Script executed:

#!/bin/bash
# Double-check: search all migration files for any reference to InstanceGroup with ordering operations
grep -r "InstanceGroup" awx/main/migrations/*.py | grep -i "options\|ordering"

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Check if ordering was already in InstanceGroup by looking at the squashed initial migrations
grep -A 20 "class InstanceGroup" awx/main/migrations/0001_initial.py | head -25

Repository: ansible/awx

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Verify workflow.py models also lack migrations for ordering
rg "class.*Meta:" awx/main/models/workflow.py -B 10 | grep "class " | head -5

Repository: ansible/awx

Length of output: 214


🏁 Script executed:

#!/bin/bash
# Check if there are any .py files in migrations directory that are uncommitted or new
git status awx/main/migrations/ 2>/dev/null || echo "Git status not available"

Repository: ansible/awx

Length of output: 120


🏁 Script executed:

#!/bin/bash
# Explicitly check 0077 migration to confirm InstanceGroup is NOT included
grep -n "InstanceGroup\|instance_group" awx/main/migrations/0077_v360_add_default_orderings.py

Repository: ansible/awx

Length of output: 121


🏁 Script executed:

#!/antml:bash
# Final check: list all AlterModelOptions operations across ALL migrations
rg "AlterModelOptions" awx/main/migrations/*.py -B 2 -A 2 | grep -E "(name=|ordering)" | head -30

Repository: ansible/awx

Length of output: 3123


🏁 Script executed:

#!/an/bash
# Check what the InstanceGroup AlterModelOptions in 0191 actually contains
sed -n '/instancegroup/,/^        \)/p' awx/main/migrations/0191_add_django_permissions.py | head -20

Repository: ansible/awx

Length of output: 104


🏁 Script executed:

#!/antml/bash
# Get the full context around InstanceGroup in 0191_add_django_permissions.py
rg -A 5 "name='instancegroup'" awx/main/migrations/0191_add_django_permissions.py

Repository: ansible/awx

Length of output: 583


A migration for the ordering change is missing from this PR.

The ordering = ('pk',) addition to InstanceGroup.Meta (line 488) is present in the model code but has no corresponding Django migration. Django tracks all Meta.ordering changes in the migration state, even when they produce no SQL schema changes. Create a new migration to document this model state change, similar to existing migrations like 0077_v360_add_default_orderings.py or 0191_add_django_permissions.py that use AlterModelOptions for InstanceGroup. Apply the same requirement to any corresponding changes in workflow.py.

🧰 Tools
🪛 Ruff (0.15.1)

[warning] 489-489: Mutable default value for class attribute

(RUF012)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@awx/main/models/ha.py` around lines 486 - 491, The InstanceGroup.Meta
ordering was changed to ordering = ('pk',) but no Django migration was added;
create a new migration that uses migrations.AlterModelOptions to record the
ordering change for the InstanceGroup model (similar to existing migrations like
0077_v360_add_default_orderings.py or 0191_add_django_permissions.py), and if
you made a parallel Meta.ordering change in any workflow-related model (e.g., in
workflow.py), include an AlterModelOptions entry for that model as well; ensure
the migration module is named/numbered consistently, imports the correct app
label 'main', and only alters the model options (no schema changes).

@sonarqubecloud
Copy link

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.

1 participant