Save + null prototype object = Cannot convert object to primitive value
See original GitHub issueIssue type:
[x] bug report
Database system/driver:
[x] postgres
(but likely not db specific)
TypeORM version:
[x] latest
Steps to reproduce or a small repository showing the problem:
Error + stack:
error: GraphQL failure: TypeError: Cannot convert object to primitive value
at Array.join (<anonymous>)
at Array.toString (<anonymous>)
at isNaN (<anonymous>)
at Function.Object.<anonymous>.OrmUtils.compare2Objects (/Users/markcrawshaw/Code/metamap-server/src/util/OrmUtils.ts:171:13)
at Function.Object.<anonymous>.OrmUtils.deepCompare (/Users/markcrawshaw/Code/metamap-server/src/util/OrmUtils.ts:118:23)
at /Users/markcrawshaw/Code/metamap-server/src/persistence/SubjectChangedColumnsComputer.ts:90:38
Error reported when null prototype object is passed. It is due to global isNaN
not being safe with null prototype objects. It can be fixed by either correcting the order of the if conditions or by using Number.isNaN
.
util/OrmUtils.ts@compare2Objects
from
if (isNaN(x) && isNaN(y) && typeof x === "number" && typeof y === "number")
to
if (typeof x === "number" && typeof y === "number" && isNaN(x) && isNaN(y))
And if you’re wondering if global isNaN
could really do this, try this:
let result;
const nullProtoObject = Object.create(null);
nullProtoObject.prop = "value";
try {
isNaN(nullProtoObject);
}
catch (e) {
result = `isNaN NOT SAFE (${e})`;
}
console.info(result || "isNaN SAFE")
Regards, Mark.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Cannot convert object to primitive value - Stack Overflow
most of the Javascript objects have toString() method inherited from Object.prototype . but some of them that have a null prototype , not...
Read more >TypeError: Cannot convert object to primitive value · Issue #2065
Many other projects are trying to create Objects by Object.create(null) , which results in [Object: null prototype] . However, there are so many ......
Read more >Object to primitive conversion - The Modern JavaScript Tutorial
So, when the conversion looks for a toString function in obj , if it doesn't find it there then it keeps looking for...
Read more >Cannot convert object to primitive value | The Node.js Master ...
Enroll now: https://pirple.thinkific.com/courses/the-nodejs-master-class.
Read more >typeerror: cannot convert object to primitive value - You.com
What's causing this error-message in general is that the system tries to convert some object to a string but can not produce a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m going to publish a new release this Friday. Thanks!
No worries @pleerock, thanks @zbessette! This will fix the issue.
Closing as available in next release.