Skip to content

fix: empty string vs nil handling for limit parameter#16375

Open
pb82 wants to merge 3 commits intodevelfrom
AAP-60861
Open

fix: empty string vs nil handling for limit parameter#16375
pb82 wants to merge 3 commits intodevelfrom
AAP-60861

Conversation

@pb82
Copy link
Copy Markdown
Contributor

@pb82 pb82 commented Mar 30, 2026

SUMMARY

Treat an empty string as no value set for prompted fields and don't store the empty string value. This allows node level fields in a workflow to override them.

ISSUE TYPE
  • New or Enhanced Feature
COMPONENT NAME
  • API
STEPS TO REPRODUCE AND EXTRA INFO
devel

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where empty-string limit values at the workflow job level were incorrectly overriding explicitly configured node-level limits during job execution. Node-level limits are now properly preserved when workflow job limits are empty.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e00bc61-c635-4b4c-96b2-c82088086802

📥 Commits

Reviewing files that changed from the base of the PR and between 6e80952 and 4f231ae.

📒 Files selected for processing (2)
  • awx/main/models/workflow.py
  • awx/main/tests/functional/models/test_workflow.py
✅ Files skipped from review due to trivial changes (1)
  • awx/main/tests/functional/models/test_workflow.py

📝 Walkthrough

Walkthrough

This PR modifies the workflow job node prompt data merging logic to filter out empty-string values from workflow job prompts before updating node prompts. It includes a functional test that verifies a workflow job node's limit is not overridden by an empty-string workflow job limit.

Changes

Cohort / File(s) Summary
Workflow Model Logic
awx/main/models/workflow.py
Modified WorkflowJobNode.get_job_kwargs() to filter out empty-string prompt values from workflow job data before merging into node prompt data, preventing empty strings from overwriting explicit node-level values.
Workflow Test
awx/main/tests/functional/models/test_workflow.py
Added functional test test_node_limit_not_overridden_by_empty_string_wj_limit to verify that a workflow job's empty-string limit does not suppress a workflow job node's explicit limit when constructing job kwargs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.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 summarizes the main change: fixing how empty strings versus nil/null values are handled for the limit parameter in prompted fields.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch AAP-60861

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
Copy Markdown

@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.

🧹 Nitpick comments (1)
awx/main/tests/functional/models/test_workflow.py (1)

304-309: Assert the normalization contract directly in this test.

This test proves downstream behavior, but it should also verify that wj.limit = '' removes limit from char_prompts (root contract). The current inline comment also reflects pre-fix behavior.

Proposed test tightening
-        # This stores '' in char_prompts instead of treating it as None/"no limit".
+        # Empty string should be normalized to "unset" (removed from char_prompts).
         wj = WorkflowJob.objects.create(name='test-wf-job')
-        wj.limit = ''  # stores {'limit': ''} in char_prompts - the IaC bug scenario
+        wj.limit = ''
         wj.save()
+        assert 'limit' not in wj.char_prompts

Also applies to: 315-319

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

In `@awx/main/tests/functional/models/test_workflow.py` around lines 304 - 309,
Add explicit assertions in this test to verify the normalization contract: after
creating wj = WorkflowJob(...), setting wj.limit = '' and calling wj.save()
assert that wj.char_prompts does not contain the 'limit' key (or that its value
is None/removed), and repeat the same explicit assertion for the similar case
around lines 315-319; locate the logic via the WorkflowJob model, the limit
attribute mutation, and the char_prompts field to implement the checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@awx/main/tests/functional/models/test_workflow.py`:
- Around line 304-309: Add explicit assertions in this test to verify the
normalization contract: after creating wj = WorkflowJob(...), setting wj.limit =
'' and calling wj.save() assert that wj.char_prompts does not contain the
'limit' key (or that its value is None/removed), and repeat the same explicit
assertion for the similar case around lines 315-319; locate the logic via the
WorkflowJob model, the limit attribute mutation, and the char_prompts field to
implement the checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dc19cc82-4805-4473-bae0-82693e5db7d3

📥 Commits

Reviewing files that changed from the base of the PR and between cd7f6f6 and 6e80952.

📒 Files selected for processing (2)
  • awx/main/tests/functional/models/test_workflow.py
  • awx/main/utils/common.py

node_prompts_data.update(wj_prompts_data)
# Empty string values on the workflow job (e.g. from IaC setting limit: "")
# should not override a node's explicit non-empty prompt value
node_prompts_data.update({k: v for k, v in wj_prompts_data.items() if v != ''})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The workflow job prompts actually do distinguish not-set versus "". Empty string indicates "target all hosts". And the UI should have this implemented correctly on its side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@AlanCoding so the current behavior is actually the correct one?

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.

4 participants