-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
Maximum call stack size exceeded - ArrayType + TsMorphMetadataProvider + findAndCount - clone #3720
Comments
I tried your change but there is still a call stack size exceeded when _joins is used in the same constellation. On our codebase: Repro: import { ArrayType, Entity, MikroORM, OneToOne, PrimaryKey, Property, Ref } from '@mikro-orm/core';
import type { PostgreSqlDriver } from '@mikro-orm/postgresql';
import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
@Entity()
export class A {
@PrimaryKey()
id!: number;
@Property({ type: ArrayType })
types!: string[];
@OneToOne()
other!: Ref<B>;
}
@Entity()
export class B {
@PrimaryKey()
id!: number;
@OneToOne({ mappedBy: 'other' })
other!: Ref<A>;
}
describe.only('GHXXXX', () => {
let orm: MikroORM<PostgreSqlDriver>;
beforeAll(async () => {
orm = await MikroORM.init({
cache: {
enabled: false,
},
entities: [A, B],
dbName: 'my-db-name',
metadataProvider: TsMorphMetadataProvider,
type: 'postgresql',
});
await orm.schema.refreshDatabase();
});
afterAll(() => orm.close(true));
test('no stackoverflow should occur', async () => {
await orm.em.createQueryBuilder(A).leftJoin('other', 'other').getCount();
});
}); |
Oh right, I know what caused it, the platform on the custom type, otherwise, it was fine to clone the metadata instances. |
It was fine to clone the metadata, but ist it needed? Even without cycle the metadata should be relativ constant and is rather large for a deep clone or am i missing something? |
Yeah, but that's much more complex refactoring, there are potentially many places like this. Feel free to send a PR, I will go with the simple way 🤷 edit: But maybe there is easy way to go about this, as the clone implementation is now inlined so we can tweak it a bit to just pass the entity metadata instance. |
That's more than enough for me, i lost hours here. I will try to create one, if i ever see it in the perf-tab. |
It's working fine now. Thank you very much. |
Describe the bug
When using findAndCount some properties of qb are cloned:
packages/knex/src/query/QueryBuilder.ts
Inside some of these properties is metadata (_aliases.c0.metadata for example) which also gets cloned (intentional?). In some cases it becomes a cycle until the stack size is exceeded. I tried to figure out when it occurs:
Even if you activate the cache and restart orm by closing and init it again, it stils fails to clone metadata/customType.
Stack trace
To Reproduce
Additional context
Not from the test above but our productive code (TreeNodeEntity contains an ArrayType)
_aliases.c0.metadata.indexes.node.targetMeta.properties.types.customType.platform.config.cache...
Versions
The text was updated successfully, but these errors were encountered: