TypeError: Cannot convert object to primitive value
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.0
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I am using NestJs with Typeorm
I get the request object form graphql, graphql parameters do not have __proto__
set.
I am directly passing the graphql paramter object to the save method. I am getting the below error when I do that:
TypeError: Cannot convert object to primitive value
at new MustBeEntityError (/Users/shashikiranms/projects/vcbackend/src/error/MustBeEntityError.ts:10:43)
at EntityPersistExecutor.execute (/Users/shashikiranms/projects/vcbackend/node_modules/typeorm/persistence/EntityPersistExecutor.js:77:35)
at EntityManager.save (/Users/shashikiranms/projects/vcbackend/src/entity-manager/EntityManager.ts:298:14)
at UserRepository.Repository.save (/Users/shashikiranms/projects/vcbackend/src/repository/Repository.ts:138:29)
When I debugged the issue, it is beacause
EntityPersistExecutor.js checks for the entity to be an instanceof Object, which is false, because __proto__
is not set for the entity
if (!this.entity || !(this.entity instanceof Object)) {
return Promise.reject(new MustBeEntityError_1.MustBeEntityError(this.mode, this.entity));
}
I think changing the above condition this.entity instanceof Object
to typeof this.entity === 'object'
solves the problem
PS: It was working in version 0.1.20. It is breaking once I upgraded to 0.2.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (5 by maintainers)
Top GitHub Comments
Just ran into this issue using type-graphql, typeorm and nestjs and was scratching my head for a while. This is a really obtuse issue and causes silent bugs. There are workarounds but it really needs to be fixed.
I solved it for my use case in NestJS with a simple object spread (required for input):
Hope it helps…