#36832: Django DB connection returns incorrect type for JSON objects with a top-
level list
-------------------------------------+-------------------------------------
Reporter: Christophe Pettus | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Test case here:
https://github.com/Xof/django_test_str
Back to at least Django 4.0, there is a bug in the database interface
under
specific conditions:
1. PostgreSQL.
2. The cursor is created from the `django.connection` object.
3. The data type being returned is JSON.
4. The top-level structure in the JSON blog is a list, rather than an
object.
In that situation, `cursor.execute` returns a `str` rather than a Python
`list`.
This bug does not exist if the query is executed using `psycopg2`
directly.
This test case should be self-contained, although you do need a local
PostgreSQL
database. The only dependency besides Django is `psycopg2`.
To run the test, use:
{{{
./manage.py test --keepdb
}}}
(`--keepdb` is not strictly required, but it avoids some unrelated
errors.)
--
Ticket URL: <
https://code.djangoproject.com/ticket/36832>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.