{
"message": "Maximum call stack size exceeded",
"stack": "RangeError: Maximum call stack size exceeded\n at formatRaw (node:internal/util/inspect:1060:50)\n at formatValue (node:internal/util/inspect:839:10)\n at inspect (node:internal/util/inspect:363:10)\n at formatWithOptionsInternal (node:internal/util/inspect:2297:40)\n at formatWithOptions (node:internal/util/inspect:2159:10)\n at console.value (node:internal/console/constructor:342:14)\n at console.log (node:internal/console/constructor:379:61)\n at Function.beforeUpdateHook (/my-app-source/Models/User.ts:271:15)\n at Hooks.exec (/my-app-source/node_modules/@adonisjs/lucid/node_modules/@poppinss/hooks/build/src/Hooks/index.js:129:23)\n at Proxy.save (/my-app-source/node_modules/@adonisjs/lucid/build/src/Orm/BaseModel/index.js:1379:28)"
}
I can observe that this beforeUpdate() hook is getting called recursively non-stop unless I kill the server. See screenshot:
Interestingly, the following snippet does not fail:
if (user.$dirty.billingPlan === 'promoter') {
const exists = await user.related('promoter').query().first()
if (!exists) {
await user.related('promoter').create({ id: user.id })
}
}
It seems to be an issue with the firstOrCreate() method.
Package version
18.4.2
Describe the bug
I have noticed that trying to create a related model from an update hook causes an infinite loop which blows up the stack.
See the following code:
When attempting to update the user via the following code:
The server crashes out with the following error:
I can observe that this beforeUpdate() hook is getting called recursively non-stop unless I kill the server. See screenshot:
Interestingly, the following snippet does not fail:
It seems to be an issue with the
firstOrCreate()
method.Will put together a repro repo if I have time
Reproduction repo
No response