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.

'Converting circular structure to JSON' when sync() is called (5.21.2)

See original GitHub issue

Issue Description

What are you doing?

To test creating DB schemas, I called sync(). And, I got the message “Unhandled rejection TypeError: Converting circular structure to JSON” regardless ‘force’ is ‘true’ or ‘false’

  • DB connection and Model definitions
const Sequelize = require('sequelize');
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS,{
  host: process.env.DB_HOST,
  dialect: 'mariadb', // I just tried to put 'mysql' with mariadb, and it showed same output with warning messages.
  dialectOptions: {
    collate: 'utf8mb4_general_ci',
    useUTC: false, 
    timezone: 'Etc/GMT0'
  }
})

module.exports = {
  sequelize: sequelize,
  User: sequelize.define('user', {
    name: Sequelize.STRING
  })
}
  • The code calling sync()
sequelize.sync({force: false })
            .then(done)
            .catch((err) => { throw err })

What do you expect to happen?

It should created a table with fields

What is actually happening?

  • Stack Trace with ‘dialect: mariadb’
Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `users`
Unhandled rejection TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Sequelize'
    |     property 'dialect' -> object with constructor 'MariadbDialect'
    --- property 'sequelize' closes the circle
    at JSON.stringify (<anonymous>)
    at ./node_modules/mocha/lib/runnable.js:422:64
    at tryCatcher (./node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (./node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (./node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (./node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (./node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (./node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (./node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (./node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (./node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)
  • Stack Trace with ‘dialect: mysql’
Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `users`
Unhandled rejection TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Sequelize'
    |     property 'dialect' -> object with constructor 'MysqlDialect'
    --- property 'sequelize' closes the circle
    at JSON.stringify (<anonymous>)
    at ./node_modules/mocha/lib/runnable.js:422:64
    at tryCatcher (./node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (./node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (./node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (./node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (./node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (./node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (./node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (./node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (./node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

Additional context

Add any other context or screenshots about the feature request here.

Environment

  • Sequelize version: 5.21.2
  • Node.js version: 12.12.0
  • Operating System: macOS Catalina 10.15.1
  • DB : Ver 15.1 Distrib 10.4.6-MariaDB, for osx10.15
  • NPM : 6.12.0

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don’t know how to start, I would need guidance.
  • No, I don’t have the time, although I believe I could do it if I had the time…
  • No, I don’t have the time and I wouldn’t even know how to start.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Ch3rlOcommented, Aug 7, 2020

As @Swadish says This problem shows when I try to destructure an object something like that

const fullEmployee = (user, lang = 'ar') => ({
  ...user,
  location: lang === 'ar' ? user.location.name : user.location.name_en,
  skills: user.employee.skills.map(({ id, name }) => ({ id, name })),
})

So what I did to fix it

const fullEmployee = (user, lang = 'ar') => ({
  ...user.dataValues,
  location: lang === 'ar' ? user.location.name : user.location.name_en,
  skills: user.employee.skills.map(({ id, name }) => ({ id, name })),
})
3reactions
jmen95commented, Jul 20, 2020

I have the same problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is TypeError: Converting circular structure to JSON?
TypeError: Converting circular structure to JSON occurs when you try to reference your variable name within the JSON object.
Read more >
TypeError: Converting circular structure to JSON in nodejs
JSON doesn't accept circular objects - objects which reference themselves. JSON.stringify() will throw an error if it comes across one of ...
Read more >
TypeError: Converting circular structure to JSON in JS
The "Converting circular structure to JSON" error occurs when we pass an object that contains circular references to the JSON.stringify() method.
Read more >
Version 5 - 5.21.2 Release Notes - What is Decisions?
Decisions 5 is a major release that is a face lift to the End User Portal and the designers. The primary focus of...
Read more >
eval EJSON returns TypeError: Converting circular structure to ...
Expecting property name enclosed in double quotes: leads me to attempt to wrap my find query in --eval “EJSON.stringify…
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