Skip to content

fix(api): allow label disassociation over limit - #16651

Open
demonpig wants to merge 2 commits into
ansible:develfrom
demonpig:AAP-92665
Open

demonpig wants to merge 2 commits into
ansible:develfrom
demonpig:AAP-92665

Conversation

@demonpig

@demonpig demonpig commented Sep 12, 2026

Copy link
Copy Markdown

SUMMARY

Allow label disassociation through the API when a resource already has more than the maximum of 100 labels.

The label attach/detach endpoint uses the same POST handler for both operations. The label-count guard previously ran for disassociation requests as well, preventing an over-limit resource from removing labels and recovering to a valid state. The guard now applies only to attach/create requests, while disassociation remains available. A unit test verifies that disassociation skips the label-count query.

ISSUE TYPE

  • Bug, Docs Fix or other nominal change

COMPONENT NAME

  • API

STEPS TO REPRODUCE AND EXTRA INFO

  1. Associate more than 100 labels with a supported resource, such as a job template.

  2. Send a request to the resource's labels endpoint to disassociate one of its labels:

    POST /api/v2/job_templates/<job_template_id>/labels/
    {"id": <label_id>, "disassociate": true}
    
  3. Before this change, the request was rejected with HTTP 400 because the label-count limit was checked before disassociation. After this change, the label is disassociated successfully.

The 100-label limit remains enforced for new label attachments.

# Attach 101 labels
for i in $(seq -w 1 101); do
  curl -sk -u admin:<password> -X POST \
    "https://<controller-host>/api/v2/job_templates/8/labels/" \
    -H "Content-Type: application/json" \
    -d "{\"name\": \"label-${i}\", \"organization\": 1}"
done

# Before: disassociate fails
curl -sk -u admin:<password> -X POST \
  "https://<controller-host>/api/v2/job_templates/8/labels/" \
  -H "Content-Type: application/json" \
  -d '{"id": 105, "disassociate": true}'
# HTTP 400 {"msg":"Maximum number of labels for job template reached."}

# After: disassociate succeeds
curl -sk -u admin:<password> -X POST \
  "https://<controller-host>/api/v2/job_templates/8/labels/" \
  -H "Content-Type: application/json" \
  -d '{"id": 105, "disassociate": true}'
# HTTP 204

Summary by CodeRabbit

  • Bug Fixes

    • Disassociating labels from objects that exceed the 100-label limit now works correctly.
    • Disassociation requests bypass label-limit validation, allowing recovery actions to proceed without an unnecessary error.
    • Label removal remains available even when an object is already over the maximum label count.
  • Tests

    • Added coverage confirming that disassociation requests bypass the label-limit check and complete successfully.

Co-Authored-By: gpt-5.6-luna <noreply@openai.com>
Signed-off-by: Max Mitschke <mmitschk@redhat.com>
@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 460869db-fdf5-4357-8136-ea143835cf22

📥 Commits

Reviewing files that changed from the base of the PR and between 61e7815 and b308393.

📒 Files selected for processing (1)
  • awx/main/tests/unit/api/test_views.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • awx/main/tests/unit/api/test_views.py

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The label endpoint now bypasses the 100-label limit for disassociation requests. A unit test verifies that label filtering is skipped and unattach is called.

Changes

Label disassociation recovery

Layer / File(s) Summary
Disassociation limit bypass
awx/api/views/labels.py, awx/main/tests/unit/api/test_views.py
The POST handler skips the label-count check when disassociate is present. The unit test verifies that Label.objects.filter is not called and unattach receives the request.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to b3083

The change preserves the attachment limit while allowing label disassociation, with targeted unit coverage for the bypass behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing API label disassociation when the label limit is exceeded.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Co-Authored-By: gpt-5.6-luna <noreply@openai.com>
Signed-off-by: Max Mitschke <mmitschk@redhat.com>
@sonarqubecloud

Copy link
Copy Markdown

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