strapi / strapi

🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable and developer-first.
https://strapi.io
Other
60.66k stars 7.58k forks source link

[Strapi 5 Beta] Maximum call stack size exceeded error when using a self-referencing relationship #20187

Open anderland opened 2 weeks ago

anderland commented 2 weeks ago

Bug report

Environment: development Node.js version: v18.18.2 NPM version: 9.8.1 Strapi version: 5.0.0-beta.4 Database: postgreSQL Operating system: macOS Javascript

Description

When populating a self-referencing relationship I consistently get error: Maximum call stack size exceeded. This is true for oneToOne, oneToMany and manyToMany.

Expected behavior

The self-referencing relationship would work like it did in Strapi 4, without errors

Screenshots

Screenshot 2024-04-23 at 12 44 13 PM

Code snippets

"parent": { "type": "relation", "relation": "manyToOne", "target": "api::module.module", "inversedBy": "children" }, "children": { "type": "relation", "relation": "oneToMany", "target": "api::module.module", "mappedBy": "parent" }

Additional context (console log)

[2024-04-23 10:27:57.767] error: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded at String.indexOf (<anonymous>) at wrapString (/my-project/node_modules/knex/lib/formatter/wrappingFormatter.js:139:39) at wrapString (/my-project/node_modules/knex/lib/formatter/wrappingFormatter.js:154:20) at wrap (/my-project/node_modules/knex/lib/formatter/wrappingFormatter.js:95:14) at get tableName [as tableName] (/my-project/node_modules/knex/lib/query/querycompiler.js:1472:11) at QueryCompiler_PG.del (/my-project/node_modules/knex/lib/dialects/postgres/query/pg-querycompiler.js:85:13) at QueryCompiler_PG.toSQL (/my-project/node_modules/knex/lib/query/querycompiler.js:75:29) at unwrapRaw (/my-project/node_modules/knex/lib/formatter/wrappingFormatter.js:102:41) at Client_PG.parameter (/my-project/node_modules/knex/lib/client.js:409:12) at QueryCompiler_PG.\_valueClause (/my-project/node_modules/knex/lib/query/querycompiler.js:988:21)

I tried to reproduce the error in a quickstart instance but it seems to work there so it must be in some way related to the db.

petrmifek commented 2 weeks ago

Might be related to #19977 - observing the behaviour with all relation, not only self-referencing ones.

Re repro - from my observation, a small catch is that it works for first time, which makes it easy to overlook. It starts failing only after the relation is cleared first time.

anderland commented 2 weeks ago

In my case, I am not encountering any errors with all relations, only with the self-referencing ones, even after repeating the steps described in #19977

derrickmehaffy commented 2 weeks ago

Might be related to #19977 - observing the behaviour with all relation, not only self-referencing ones.

Re repro - from my observation, a small catch is that it works for first time, which makes it easy to overlook. It starts failing only after the relation is cleared first time.

That's great reproduction information

derrickmehaffy commented 2 weeks ago

Can't reproduce with beta.5

github-actions[bot] commented 2 weeks ago

This is a templated message

Hello @anderland,

Thank you for reporting this bug, however we are unable to reproduce the issue you described given the information we have on hand. Can you please create a fresh project that you are able to reproduce the issue in, provide clear steps to reproduce this issue, and either upload this fresh project to a new GitHub repo or compress it into a .zip and upload it on this issue?

We would greatly appreciate your assistance with this, by working in a fresh project it will cut out any possible variables that might be unrelated. Please note that issues labeled with status: can not reproduce will be closed in 14 days if there is no activity.

Thank you!

petrmifek commented 2 weeks ago

Unfortunately we're still seeing this issue with beta.5

I took the liberty to prop up a repository with a sample docker compose environment to reproduce the issue, I still can reproduce it on beta5, hopefully it's not just used wrong...

The repository is at https://github.com/anapol/strapi5-repro

It contains 3 branches and a readme how to repro:

Thanks!

petrmifek commented 2 weeks ago

The issue seems to be exclusively related to PostgreSQL, SQLite and MySQL seems to be working fine in both cases.

derrickmehaffy commented 2 weeks ago

The issue seems to be exclusively related to PostgreSQL, SQLite and MySQL seems to be working fine in both cases.

Gotcha, I was testing with SQLite so that makes sense. Will test with PG then.

kasonde commented 1 week ago

Confirmed in beta.5