Skip to content

Fix new code list with multiple codes failing to save (#878)#894

Open
simonreed wants to merge 1 commit into
developfrom
new-code-list-with-multiple-codes-fails-to-save-878
Open

Fix new code list with multiple codes failing to save (#878)#894
simonreed wants to merge 1 commit into
developfrom
new-code-list-with-multiple-codes-fails-to-save-878

Conversation

@simonreed
Copy link
Copy Markdown
Contributor

Fixes a bug where creating a new code list with two or more codes in a single submit would fail silently. The create path in CodeListForm.js did not assign order values to codes before sending to the server, while the update path did. With one code, order collisions don't occur; with two or more codes both lacking order, the server's fallback doesn't reliably produce distinct values in a single transaction.

The fix assigns order = i + 1 to every code before both create and update dispatches, removing the asymmetry. A backend controller cleanup replaces map.with_index (which left nils in the array) with each_with_index for blank-row filtering. A new backend test covers POST-create with two codes and no client-supplied order. A Playwright regression feature file verifies the full flow end-to-end. Save failures now surface a visible error rather than failing silently.

Round 2 Changes

Round 1 failed on process only: the PR creation tool exited with an error because it constructed the OAuth token URL incorrectly, resolving to the wrong path. The block-direct-pr.sh hook prohibited any fallback. No code changes were needed in round 2 — the fix corrects the OAuth path resolution in the PR creation tool and adds a flag to specify the correct base branch when project settings lack a default_branch value.

All code was independently verified in round 1: 13 backend test runs, 0 failures, Playwright flow green, brakeman clean.

Verification failures from round 1

  • A pull_request artifact exists recording the GitHub PR URL — No artifact of kind pull_request was recorded. The PR creation tool failed with exit 1 due to an OAuth token URL path bug. Branch new-code-list-with-multiple-codes-fails-to-save-878 was pushed to origin and ready for PR against develop, but no PR was opened.

Frontend: assign code.order in the create path (matching the update
path). Backend: replace map.with_index with each_with_index to make
intent clear. Guard err.response access with optional chaining so a
network error does not raise a secondary TypeError.

Adds a backend controller test and a Playwright flow regression test.
Also adds fixtures :all to test_helper.rb which was missing, causing
all controller/model tests to fail with undefined method 'users'.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@simonreed simonreed marked this pull request as ready for review April 27, 2026 23:31
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.

1 participant