question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Save + null prototype object = Cannot convert object to primitive value

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
pleerockcommented, Feb 26, 2020

I’m going to publish a new release this Friday. Thanks!

0reactions
mcrawshawcommented, Feb 26, 2020

No worries @pleerock, thanks @zbessette! This will fix the issue.

Closing as available in next release.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found