You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
toJSON converting booleans to "t" (true) or "f" (false) #8749
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue type
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
I don't know whether it's possible to have a test case for this. What I do know is that when you connect the latest sequelize releases to a postgres database, and query a model with a boolean column, the values come back as 't' and 'f'.
The most recent release that correctly returns bools from postgres is 4.25.2. Perhaps something introduced with postgres support for enums broke the bool typecasting?
With release 4.26.0 (and 4.28.6), I have a model A with a boolean property prop. The returned instance from A.create(...) has prop='t', whereas reloading causes the value to be properly casted.
I noticed this problem when doing finds with { raw: true }, instead of calling toJSON() explicitly.
I struggled to reproduce it in an isolated example, but your comments about ENUMs have helped me and I now have something that can reliably reproduce it for me. It only happens when I define an ENUM field.
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue type
Activity
karn09 commentedon 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.
jonahlau commentedon Dec 5, 2017
@karn09 Ah, yes sorry for the typo. I did mean 4.26.0
Downgrading to 4.25.2 fixed it for me. So should I avoid upgrading to latest release until this is resolved?
karn09 commentedon Dec 5, 2017
@jonahlau until it's fixed probably a good idea, unless you need the fixes in the newer version more then proper booleans on toJSON.
dee-el commentedon Dec 6, 2017
I seeing same issue with
Nodejs version : v8.1.4
OS version : Ubuntu 16.04
DB dialect: postgress
tapz commentedon Dec 11, 2017
4.28.0 still has this issue.
sushantdhiman commentedon Dec 16, 2017
FYI I tried to replicate this issue but failed, #8791 (test case)
If some one can add a reproducible test case I will take care of fixing it
aaltepet commentedon Dec 19, 2017
I don't know whether it's possible to have a test case for this. What I do know is that when you connect the latest sequelize releases to a postgres database, and query a model with a boolean column, the values come back as 't' and 'f'.
The most recent release that correctly returns bools from postgres is 4.25.2. Perhaps something introduced with postgres support for enums broke the bool typecasting?
With release 4.26.0 (and 4.28.6), I have a model
Awith a boolean propertyprop. The returned instance fromA.create(...)hasprop='t', whereas reloading causes the value to be properly casted.const instance = await A.create({ prop: true }); instance.dataValues.prop === 't'; await instance.reload(); instance.dataValues.prop === truetapz commentedon Dec 19, 2017
't' probably is what Postgre returns. There seems to be no conversion to JS boolean from the string value returned by Postgre.
sushantdhiman commentedon Dec 20, 2017
But you guys are facing this issue consistently on at least one machine, lets start with that.
Please share your setup details (as much as possible) and answer these questions
tapz commentedon Dec 20, 2017
Our system has some unit tests, which produce this issue every time when run with 4.28.6. I run the tests on my own machine.
MacOS 10.13.2 (17C88)
Node 8.9.3
Postgres 9.6.2
pg 6.4.2
pg-native 2.2.0 (not sure if really used)
We do have some ENUMs defined, but not in the same table where the booleans do not work.
aaltepet commentedon Dec 20, 2017
Our system has some unit tests which produce this issue when run with 4.28.6. We run the tests within a docker-compose environment.
Node image: node:8.9.0
Postgres image: postgres:9.6.1
sequelize: 4.28.6
pg: 6.1.2
To narrow down the test, I did the following in my environment:
created a new model:
Created a mocha/chai test to verify behavior:
Output from mocha:
rokoroku commentedon Dec 27, 2017
Same here
Even creating a new model with default valued boolean fields, it returns
't'or'f', exactly likeabove example by @aaltepet
And downgrading to 4.25.2 fixed it temporarily.
kapvode commentedon Jan 2, 2018
I noticed this problem when doing finds with
{ raw: true }, instead of callingtoJSON()explicitly.I struggled to reproduce it in an isolated example, but your comments about ENUMs have helped me and I now have something that can reliably reproduce it for me. It only happens when I define an ENUM field.
These are my versions:
themetalfleece commentedon Jan 3, 2018
I'm facing the same problem @4.28.6 (postgres) when running the following.
the returned object has 't' or 'f' instead of booleans
emhagman commentedon Jan 5, 2018
+1 Having this issue, our tests caught this.
Happens when using
{ raw: true }on thefindOne()Can confirm that Sequelize
4.25.2fixes the test as well.sushantdhiman commentedon 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 #8851 patch and verify if that fix this issue. After verification and review from other maintainers I will merge that PR.
tapz commentedon Jan 7, 2018
Well done @sushantdhiman, the fix seems to work with my test cases!
kapvode commentedon Jan 8, 2018
It works for me too. Thank you.