Skip to content

fix: dispatch original entity id in DeletedEventDTO, not a post-flush getId()#575

Merged
smarcet merged 1 commit into
mainfrom
hotfix/domain-events-remove
Jul 25, 2026
Merged

fix: dispatch original entity id in DeletedEventDTO, not a post-flush getId()#575
smarcet merged 1 commit into
mainfrom
hotfix/domain-events-remove

Conversation

@smarcet

@smarcet smarcet commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

ref: https://app.clickup.com/t/9014802374/86bb35agx

Doctrine nulls an entity's identifier field via reflection after a hard delete is flushed (UnitOfWork::executeDeletions). DeletedEventDTO::fromEntity() was being called after the owning transaction closed, so it read that stale, zeroed id and dispatched 'id' => 0 in the domain event payload.

Added DeletedEventDTO::fromId() and switched the affected dispatch call sites to build the DTO from the id captured before removal:

  • SummitSponsorshipService::removeSponsorship / removeAddOn
  • SummitSponsorService::deleteSponsor
  • SummitMediaFileTypeService::delete

Also applied the same fromId() call in SummitService::deleteSummit for consistency, though that path only flips a soft-delete flag (no em->remove()), so it never actually reproduced the zeroed-id bug.

Added regression tests for all four dispatch paths, verified against the pre-fix code to confirm they fail with the original id => 0 defect (SummitService's stays green either way, per the note above).

Summary by CodeRabbit

  • Bug Fixes

    • Corrected deletion events so they consistently include the original record ID.
    • Improved event accuracy for deleted summits, sponsors, sponsorships, add-ons, and media file types.
    • Prevented deleted-record events from containing missing, zero, or outdated identifiers.
  • Tests

    • Added coverage validating deletion event payloads across supported sponsor service operations.

… getId()

Doctrine nulls an entity's identifier field via reflection after a hard
delete is flushed (UnitOfWork::executeDeletions). DeletedEventDTO::fromEntity()
was being called after the owning transaction closed, so it read that
stale, zeroed id and dispatched 'id' => 0 in the domain event payload.

Added DeletedEventDTO::fromId() and switched the affected dispatch call
sites to build the DTO from the id captured before removal:

- SummitSponsorshipService::removeSponsorship / removeAddOn
- SummitSponsorService::deleteSponsor
- SummitMediaFileTypeService::delete

Also applied the same fromId() call in SummitService::deleteSummit for
consistency, though that path only flips a soft-delete flag (no
em->remove()), so it never actually reproduced the zeroed-id bug.

Added regression tests for all four dispatch paths, verified against the
pre-fix code to confirm they fail with the original id => 0 defect
(SummitService's stays green either way, per the note above).
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 23727d8e-4a03-45c0-af4b-461f6744c4e7

📥 Commits

Reviewing files that changed from the base of the PR and between f510411 and 2dd7881.

📒 Files selected for processing (9)
  • app/Events/SponsorServices/DeletedEventDTO.php
  • app/Services/Model/Imp/SummitMediaFileTypeService.php
  • app/Services/Model/Imp/SummitService.php
  • app/Services/Model/Imp/SummitSponsorService.php
  • app/Services/Model/Imp/SummitSponsorshipService.php
  • tests/Unit/Services/SummitMediaFileTypeServiceEventDispatchTest.php
  • tests/Unit/Services/SummitServiceEventDispatchTest.php
  • tests/Unit/Services/SummitSponsorServiceEventDispatchTest.php
  • tests/Unit/Services/SummitSponsorshipServiceEventDispatchTest.php

📝 Walkthrough

Walkthrough

Deletion domain events now construct DeletedEventDTO instances from captured IDs across summit, sponsor, sponsorship, add-on, and media file type services. New unit tests verify queued event payloads retain the original IDs.

Changes

Deletion event payloads

Layer / File(s) Summary
DTO contract and deletion service wiring
app/Events/SponsorServices/DeletedEventDTO.php, app/Services/Model/Imp/*Service.php
Adds DeletedEventDTO::fromId() and uses it across deletion event dispatch paths.
Deletion event regression coverage
tests/Unit/Services/*EventDispatchTest.php
Adds tests asserting deletion jobs contain the original entity IDs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: romanetar

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 fix: using the original entity ID in deletion events instead of a post-flush getId().
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 hotfix/domain-events-remove

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.

@github-actions

Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-575/

This page is automatically updated on each push to this PR.

@smarcet
smarcet merged commit cea3f8b into main Jul 25, 2026
20 checks passed
smarcet added a commit that referenced this pull request Jul 25, 2026
… getId() (#575)

Doctrine nulls an entity's identifier field via reflection after a hard
delete is flushed (UnitOfWork::executeDeletions). DeletedEventDTO::fromEntity()
was being called after the owning transaction closed, so it read that
stale, zeroed id and dispatched 'id' => 0 in the domain event payload.

Added DeletedEventDTO::fromId() and switched the affected dispatch call
sites to build the DTO from the id captured before removal:

- SummitSponsorshipService::removeSponsorship / removeAddOn
- SummitSponsorService::deleteSponsor
- SummitMediaFileTypeService::delete

Also applied the same fromId() call in SummitService::deleteSummit for
consistency, though that path only flips a soft-delete flag (no
em->remove()), so it never actually reproduced the zeroed-id bug.

Added regression tests for all four dispatch paths, verified against the
pre-fix code to confirm they fail with the original id => 0 defect
(SummitService's stays green either way, per the note above).
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