Skip to content

[COMMS-1071] Create labels when the work package is saved - #26270

Draft
akabiru wants to merge 9 commits into
devfrom
implementation/comms-1071-create-labels-on-work-package-save
Draft

akabiru wants to merge 9 commits into
devfrom
implementation/comms-1071-create-labels-on-work-package-save

Conversation

@akabiru

@akabiru akabiru commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

https://community.openproject.org/wp/81938

A label typed into the work package form used to be created the moment "Create label" was picked, so an abandoned form left a ghost label behind that every editor could pick and admins saw in the labels list. Now the autocompleter keeps the new label as a local pending item, the work package payload sends it as a _links.labels entry with a null href and the name as title, and the backend finds or creates it inside the save transaction. The form endpoints echo such entries back without persisting anything, so a pending label survives form refreshes on the create form, and the contract rejects names the user may not create (same gate as POST /api/v3/labels) before anything is written. Bulk edit and move/copy forms get the same in a stacked follow-up.

A work package can carry label names next to label ids. The names are
resolved or created inside the save transaction, so an abandoned form
leaves no label behind and the contract rejects names the user may not
create before anything is written.
A `_links.labels` entry with a null href and a title is a label to
create on save; the form endpoints echo it back without persisting.
The autocompleter keeps a new label as a local pending item and the
work package payload sends it as a titled link without href.
@akabiru akabiru self-assigned this Oct 23, 2026
Comment thread app/models/concerns/labelable.rb Fixed
The form echo and the contract looked a label up per name; both now
match all names at once with the case folding done in Postgres.
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Deploying openproject with ⚡ PullPreview

Field Value
Latest commit cdb2323
Job deploy
Status ✅ Deploy successful
Preview URL https://pr-26270-comms-1071-creat-ip-46-224-163-150.my.opf.run:443

View logs

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/work_packages/cancel_editing_spec.rb[1:5]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #26270, linked for reference only):

- `rspec ./spec/features/work_packages/cancel_editing_spec.rb[1:5]`

Treat this as a standalone task, unrelated to PR #26270. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #26270 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @akabiru to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @akabiru, and request a review from @akabiru.
On every commit, set @akabiru as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

The create service ignored the result of its unvalidated save, so an aborted
label creation needed a raise to avoid a silent success and ended in a 500.
Honouring the save result turns it into the same 422 the update path gives.
Names that already exist are filtered in one query, so uniqueness and the
permission lookup no longer run once per pending name on every form refresh.
A pending label and a persisted label with the same name are the same label,
since the backend identifies labels by their lower-cased name.
Without a labels link on the reference the base changeset writes raw resources
into the payload and the pending titles were lost.

This branch has not been deployed

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

Development

Successfully merging this pull request may close these issues.

2 participants