Skip to content

fix(core): prevent orphan sites from failed SiteCreate; null-safe SiteDelete#4696

Merged
renemadsen merged 2 commits into
masterfrom
fix/sitecreate-atomic-sitedelete-nullsafe
Jun 12, 2026
Merged

fix(core): prevent orphan sites from failed SiteCreate; null-safe SiteDelete#4696
renemadsen merged 2 commits into
masterfrom
fix/sitecreate-atomic-sitedelete-nullsafe

Conversation

@renemadsen

Copy link
Copy Markdown
Member

Closes #4695.

Problem

Core.SiteCreate registers a site remotely and commits the local Sites row, then creates the EntityItems / Unit / Worker / SiteWorker in separate non-transactional steps with no rollback. If any step throws, the Sites row is left active with no Worker/SiteWorker — an orphan that permanently blocks recreating a worker by that name (downstream Sites.Name duplicate check). Separately, Core.SiteDelete NRE'd on worker-less sites (siteWorkerDto/WorkerUid dereferenced unguarded), so it couldn't be used to recover orphans.

Fix

  • SiteCreate compensating cleanup: track the remotely-created site uid (and worker uid, if reached) and, on exception, remove them via Advanced_SiteItemDelete (site + entity items + remote deregister + local soft-delete) and Advanced_WorkerDelete (worker). Each cleanup is wrapped so it never masks the original exception, which is always re-thrown. Cleanup routes through Advanced_SiteItemDelete (not SiteDelete) deliberately: SiteDeleteSiteReadSimple calls .First() on the SiteWorkers set and throws on worker-less sites, so it cannot clean an orphan; Advanced_SiteItemDelete removes the site directly.
  • SiteDelete null-safety: guard siteDto.WorkerUid != null and siteWorkerDto != null so deleting a site with no SiteWorker no longer NREs and still soft-deletes the site + entity items. Happy path (fully-formed worker) unchanged.
  • Test: Core_Advanced_SiteItemDelete_OnSiteWithoutSiteWorker_SoftDeletesSite — arranges a worker-less orphan site and asserts it is soft-deleted without throwing.

Notes / limitations

🤖 Generated with Claude Code

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@renemadsen renemadsen merged commit 64678e1 into master Jun 12, 2026
12 of 13 checks passed
@renemadsen renemadsen deleted the fix/sitecreate-atomic-sitedelete-nullsafe branch June 12, 2026 07:06
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.

Core.SiteCreate is non-atomic and leaves orphan sites; Core.SiteDelete NREs on worker-less sites

2 participants