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.

Cockroachdb sqlalchemy dialect doesn't fully support JSONB

See original GitHub issue

I’m testing recently added JSONB.

Setup:

python3.6
psycopg2==2.7.4
SQLAlchemy==1.2.5
cockroachdb v2.0.1

I was able to save a sample data into the database. This is how it looks in a dump file:

{
    "id" : "2a4b4578-1a5d-455b-9317-c90c5f3afe15",
    "enabled" : true,
    "language" : "en-us",
    "ui_metadata" : "{\"origin\": \"111\", \"ui\": null, \"version\": null}",
}

I’m now loading data with sqlalchemy session.query.all() Error:

    return json_deserializer(value)
  File "/usr/local/lib/python3.6/json/__init__.py", line 348, in loads
    'not {!r}'.format(s.__class__.__name__))
TypeError: the JSON object must be str, bytes or bytearray, not 'dict'

https://bitbucket.org/zzzeek/sqlalchemy/src/7541d9b258e4d0c115d6160592ac7e17f8fd50cc/lib/sqlalchemy/sql/sqltypes.py?at=master&fileviewer=file-view-default#sqltypes.py-2145:2155 https://github.com/cockroachdb/cockroachdb-python/blob/master/cockroachdb/sqlalchemy/dialect.py

This line fails:

json_deserializer = dialect._json_deserializer or json.loads

Because there is no _json_deserializer and it tries to call json.loads on a python dict.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bdarnellcommented, May 9, 2018

I’ve just uploaded a new version to pypi.

1reaction
despritcommented, May 7, 2018

@bdarnell

I’m not using JSON 😃

from sqlalchemy.dialects.postgresql import JSONB

class myClass(Base):
    my_field = Column(JSONB, nullable=False, default=lambda: {})

I’m using dbeaver as a gui tool and it says that data type of that column is jsonb. So when my code throws TypeError: the JSON object must be str, bytes or bytearray, not 'dict', it somehow detects JSON instead of JSONB.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cockroachdb sqlalchemy dialect doesn't fully support JSONB
I'm testing recently added JSONB. Setup: python3.6 psycopg2==2.7.4 SQLAlchemy==1.2.5 cockroachdb v2.0.1 I was able to save a sample data ...
Read more >
JSONB | CockroachDB Docs
Returns the JSON value pointed to by the variadic arguments. See Update an array element. For the full list of supported JSONB functions,...
Read more >
What's New in v21.2 | CockroachDB Docs
Sequelize, a Javascript object-relational mapper (ORM), and Alembic, a schema migration tool for SQLAlchemy users, are now fully supported. We have also ...
Read more >
What's New in v2.1 | CockroachDB Docs
CockroachDB v2.1 is no longer supported. For more details, see the Release Support Policy. Get future release notes emailed to you: *.
Read more >
What's New in v21.1 | CockroachDB Docs
The format for SQL audit, execution, and query logs has changed from a crude space-delimited format to JSON. To opt out of this...
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