fix: preserve single latest draft when saving a new identity - #7918
fix: preserve single latest draft when saving a new identity#7918Shivamkmr8 wants to merge 2 commits into
Conversation
|
@dotnet-policy-service agree company="Surya Fintech" |
There was a problem hiding this comment.
Pull request overview
Fixes #7915 by preserving a single latest workflow definition when saving a new draft identity.
Changes:
- Demotes the previous latest draft when identities differ.
- Preserves version and latest status when re-saving the same draft.
- Adds integration coverage for both scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionPublisher.cs |
Extends latest-version demotion to unpublished drafts. |
test/integration/Elsa.Workflows.IntegrationTests/Scenarios/WorkflowDefinitionVersioning/Tests.cs |
Tests new-identity and same-identity draft saves. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Greptile SummaryThe workflow draft persistence update keeps exactly one latest definition when a new draft identity replaces an unpublished draft, while preserving version and latest state when the same draft is re-saved. Focused integration coverage also confirms that persistence and notification failures do not leave committed workflow definitions in a conflicting latest state. Confidence Score: 5/5No blocking failure remains. The focused integration checks exercised replacement, re-save, persistence-failure, and notification-failure behavior and confirmed the expected persisted state.
What T-Rex did
Reviews (2): Last reviewed commit: "Merge branch 'release/3.8.0' into improv..." | Re-trigger Greptile |
f21d162 to
fbb2a8e
Compare
|
@sfmskywalker The previous Greptile issue has been addressed by persisting the previous-version demotion and the new latest version together using SaveManyAsync, with the post-save notification moved after persistence. The focused tests are passing. Could you please review the latest changes? |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionPublisher.cs:235
- The PR description states that persistence ordering is unchanged, but this batch now persists the previous-version demotion before
WorkflowDefinitionDraftSaved; previously the draft was saved and that notification was dispatched before the previous version was demoted. This materially changes notification and failure semantics (as the new notification-failure test confirms), so the description should document the ordering change rather than claim there is none.
await workflowDefinitionStore.SaveManyAsync([lastVersion, draft], cancellationToken);
| if (lastVersion is { IsLatest: true } && lastVersion.Id != draft.Id) | ||
| { | ||
| lastVersion.IsLatest = false; | ||
| await workflowDefinitionStore.SaveAsync(lastVersion, cancellationToken); | ||
| await workflowDefinitionStore.SaveManyAsync([lastVersion, draft], cancellationToken); |
3c21b26 to
2ba7c5e
Compare
|
PR author is not in the allowed authors list. |
|
@sfmskywalker I have addressed the latest Copilot comment. SaveDraftAsync now uses the highest version only to calculate the version number, and separately finds the workflow marked as IsLatest to clear its latest flag. |
Purpose
Addresses #7915 by ensuring that
SaveDraftAsyncpreserves a single latest workflow definition when saving a different draft identity for the sameDefinitionId.The change extends the existing latest-state handling to unpublished drafts while preserving the current behavior when re-saving the same draft.
Scope
Select one primary concern:
Description
Problem
SaveDraftAsyncsets the incoming workflow definition toIsLatest = true.When a previous version exists, its
IsLatestflag is currently cleared only when that version is both published and latest:This works for the standard published-to-draft flow.
However, when
SaveDraftAsyncreceives a different draft identity for the sameDefinitionIdwhile the previous latest version is unpublished, the previous version is not demoted.For example, starting with:
and saving a different draft identity creates:
This leaves multiple workflow definition versions marked as latest.
Solution
Update the condition so that the previous last version is demoted whenever:
The identity check is important because
SaveDraftAsyncalso supports re-saving the same draft.When the same draft is saved again:
the existing draft remains latest and retains its existing version number.
This results in:
No changes are made to version allocation, publication state, or persistence ordering.
Verification
Steps:
SaveDraftAsync_ShouldClearLatestFlagFromPreviousUnpublishedDraft.IsLatest = true.SaveDraftAsync_ShouldKeepExistingDraftLatestWhenResavedto protect the existing same-draft behavior.SaveDraftAsynclatest-state condition.Elsa.Workflows.IntegrationTestssuite.Expected outcome:
Test results:
Screenshots / Recordings (if applicable)
Not applicable.
Commit Convention
We recommend using conventional commit prefixes:
fix:– Bug fixes (behavior change)feat:– New featuresrefactor:– Code changes without behavior changedocs:– Documentation updateschore:– Maintenance, tooling, or dependency updatestest:– Test additions or modificationsClear commit messages make reviews easier and history more meaningful.
Related Issue
Closes #7915
Checklist