Repository navigation
fix(persistence): preserve select-false columns in entity subscriber events - #12493
mbursali93 wants to merge 2 commits into
Conversation
Code Review by Qodo
1. originalEntity! non-null assertion
|
commit: |
There was a problem hiding this comment.
Thanks for your help @mbursali93
Is this fix working for you @tada5hi @Johoseph ?
|
This PR routes only the subscriber broadcast ( Minimal repro (no subscriber): @Entity()
class User {
@PrimaryGeneratedColumn('uuid') id: string;
@Column() name: string;
@Column({ select: false }) email: string;
}
const entity = repo.create({ name: 'foo', email: '[email protected]' });
const saved = await repo.save(entity);
console.log(saved.email); // undefined on 0.3.29, '[email protected]' on 0.3.28
console.log('email' in entity); // false on 0.3.29, true on 0.3.28 (passed-in ref is mutated too)To fully restore the 0.3.28 contract, the snapshot-and-restore needs to apply to |
|
Hi @mbursali93 thanks for the contribution! We decided instead to revert the PR that introduced the bug, by merging #12501. I think it's the right thing to do considering the original issue - see #4591 (comment) |
Problem
select: falsecolumns are missing fromevent.entityin entity subscriber events (afterInsert, afterUpdate) becauseSubjectExecutormutates the entity object before broadcasting.Root Cause
SubjectExecutormanipulates the entity during execution. By the timebroadcastAfterEventsForAllis called,select: falsecolumns have been stripped from the entity.Fix
Added
snapshotEntity()method toSubjectclass that takes a shallow copy of the entity before execution begins. Broadcaster usesoriginalEntity ?? entityto ensure original values are preserved.Testing
Added integration tests for
afterInsertandafterUpdatesubscriber events verifying thatselect: falsecolumns are present.Fixes #12473