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.

toJSON converting booleans to "t" (true) or "f" (false)

See original GitHub issue

What are you doing?

I have the user model as defined below.

// User model

sequelize.define('user', {
  email: {
    type: STRING,
    allowNull: false,
    unique: true,
    validate: {
      isEmail: true,
      notEmpty: true
    }
  },
  password: {
    type: STRING,
    allowNull: false,
    visible: []
  },
  firstName: {
    type: STRING,
    allowNull: false
  },
  lastName: {
    type: STRING,
    allowNull: false
  },
  active: {
    type: BOOLEAN,
    allowNull: false,
    defaultValue: true
  },
  role: {
    type: STRING,
    allowNull: false,
    defaultValue: 'user'
  },
  isVerified: {
    type: BOOLEAN,
    defaultValue: false
  },
  resetPasswordToken: {
    type: STRING,
    allowNull: true,
    visible: []
  },
  resetPasswordExpires: {
    type: DATE,
    allowNull: true,
    visible: []
  },
  lastLogoutTime: {
    type: DATE,
    allowNull: true,
    visible: ['admin']
  }
});


What do you expect to happen?

toJSON should retain booleans and not convert them to strings

What is actually happening?

When I call toJSON of any instance of User in my CI tests (running in as a docker container with node 8.9.1), all booleans, for example fields active and isVerified, get converted to “t” or “f”.

The problem doesn’t happen when I run it on MacOS 10.12.15 running Node 8.9.1

Output, either JSON or SQL

Dialect: postgres Dialect version: XXX Database version: 9.5 Sequelize version: 4.2.0 Tested with latest release: yes (If yes, specify that version)

Note : Your issue may be ignored OR closed by maintainers if it’s not tested against latest version OR does not follow issue template.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
sushantdhimancommented, Jan 7, 2018

Thanks @kapvode for a proper test case. As suspected a model with ENUM fetch OIDs properly but wont refresh base types like BOOLEAN in this case.

Everyone please use https://github.com/sequelize/sequelize/pull/8851 patch and verify if that fix this issue. After verification and review from other maintainers I will merge that PR.

5reactions
karn09commented, Dec 4, 2017

I’m seeing this same issue, but with 4.26.0. @jonahlau Did you mean 4.26.0 as well? You had marked yes to tested with latest.

Downgrading to 4.25.2 fixed the issue for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does a JSON reader convert JSON boolean values (i.e. ...
Why does a JSON reader convert JSON boolean values (i.e. true/false) to Yes/No boolean values? I hope the title is already quite self ......
Read more >
python - Convert True/False value read from file to boolean
To convert a string to boolean you need to do something like this: ... True values are y , yes , t ,...
Read more >
Convert bool (True, False) and other types to each ... - nkmk note
In Python, truth values (Boolean values) are represented by bool type objects, True and False. Results by comparison operators are returned ...
Read more >
How to Convert True or False String to Its Corresponding ...
How to Convert True or False String to Its Corresponding Boolean Value in Javascript · 1. Using JSON.parse · 2. Using the comparison...
Read more >
Python - Convert String Truth values to Boolean
In this, we check for just the true value, and the rest of the values are automatically converted to a False boolean. Python3....
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