New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
invalid serialization of json during upsert #3787
Comments
Unfortunately, we are still seeing this with v5.6.0. |
Then please provide a complete repro, the fix included a passing test case 🤷 |
I just reproduced the same issue with upsertMany using Mikro-orm 5.6.9.
If settings:
then the problem is gone. |
Then provide the repro please, both should behave exactly the same since 5.6.9, before the |
Ok I wrote a simple test that does nothing but create two tables and insert data into them. For some reason I wasn't able to just set package.json: {
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.20.13",
"@types/jest": "^29.4.0",
"jest": "^29.4.3",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
},
"dependencies": {
"@mikro-orm/core": "^5.6.9",
"@mikro-orm/mysql": "^5.6.9"
}
} mo.test.ts import { Entity, PrimaryKey, Property } from "@mikro-orm/core";
import { MikroORM } from "@mikro-orm/mysql";
@Entity()
class MyEntity1 {
@PrimaryKey({ type: 'number' })
id!: number;
@Property({ type: 'json' })
field!: object;
}
@Entity()
class MyEntity2 {
@PrimaryKey({ type: 'number' })
id!: number;
@Property({ type: 'json', columnType: 'json' })
field!: object;
}
test('mikro-orm JSON serialization with upsertMany', async() => {
const orm = await MikroORM.init({
type: 'mysql',
dbName: 'motest',
host: '127.0.0.1',
user: 'root',
password: 'root',
port: 3378,
allowGlobalContext: true,
entities: [MyEntity1, MyEntity2]
});
await orm.schema.refreshDatabase();
const em = orm.em;
const entity1 = em.create(MyEntity1, {
id: 1,
field: {
firstName: 'John',
lastName: 'Doe'
}
});
em.upsertMany([entity1]);
const entity2 = em.create(MyEntity2, {
id: 1,
field: {
firstName: 'Albert',
lastName: 'Doe'
}
});
em.upsertMany([entity2]);
}); Looking into the database I see that for my_entity1: and for my_entity2: |
Describe the bug
we discovered that during upsert a json property is being serialized into a string. this test demonstrates that behaviour.
To Reproduce
Steps to reproduce the behavior:
#3786
Versions
we were able to reproduce this with sqlite, better-sqlite and postgres drivers (didn't test others).
The text was updated successfully, but these errors were encountered: