You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I retrieve Entity A and a nullable property has a null value, an update query on Entity A gets triggered after flushing. Seemlingly, this is because of using forceUndefined: true, and the nullable property gets converted to undefined on entity retrieval, and that gets registered as a change that has to be persisted.
This was noted as fixed in v5.7.2, but now it's happening again
To reproduce
import{Entity,PrimaryKey,Property,SimpleLogger,}from'@mikro-orm/core';import{MikroORM}from'@mikro-orm/postgresql';import{mockLogger}from'../../helpers';
@Entity()exportclassA{
@PrimaryKey({type: 'number'})id!: number;
@Property({length: 3,name: 'created_at',nullable: true,type: 'datetime',})createdAt?: Date;
@Property({length: 64,name: 'name',type: 'varchar'})name!: string;}describe('GH issue 4412',()=>{letorm: MikroORM;beforeAll(async()=>{orm=awaitMikroORM.init({dbName: ':memory:',entities: [A],forceUndefined: true,loggerFactory: options=>newSimpleLogger(options),});awaitorm.schema.refreshDatabase();});afterAll(()=>orm.close(true));test('update triggered after findOne with forceUndefined true',async()=>{constmock=mockLogger(orm);leta: A|null=orm.em.create(A,{id: 1,name: 'a',});awaitorm.em.persistAndFlush(a);a=awaitorm.em.findOne(A,{name: 'a'});awaitorm.em.flush();expect(mock.mock.calls).toEqual([['[query] begin'],["[query] insert into \"a\" (\"id\", \"name\") values (1, 'a') returning \"id\""],['[query] commit'],["[query] select \"a0\".* from \"a\" as \"a0\" where \"a0\".\"name\" = 'a' limit 1"],['[query] begin'],['[query] update "a" set "created_at" = NULL where "id" = 1'],['[query] commit'],]);});});
Versions
Dependency
Version
node
v18.16.0
typescript
5.0.4
mikro-orm
5.7.10
driver
postgresql
The text was updated successfully, but these errors were encountered:
Previous issues related to this one
#4262
#4266
Describe the bug
If I retrieve Entity
A
and a nullable property has anull
value, an update query on EntityA
gets triggered after flushing. Seemlingly, this is because of usingforceUndefined: true
, and the nullable property gets converted toundefined
on entity retrieval, and that gets registered as a change that has to be persisted.This was noted as fixed in v5.7.2, but now it's happening again
To reproduce
Versions
The text was updated successfully, but these errors were encountered: