[Django] #33424: Jsonfield data being returned as str

15 views
Skip to first unread message

Django

unread,
Jan 7, 2022, 11:25:44 AM1/7/22
to django-...@googlegroups.com
#33424: Jsonfield data being returned as str
-------------------------------------+-------------------------------------
Reporter: nitishxp | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.2
Uncategorized | Keywords: Database, Django
Severity: Normal | Cursor
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi,

I encountered a bug in raw postgresql query

from django.db.models import JSONField
from django.db import connection

class Job(models.Model):
job_dict = JsonField()


def view(request):
with connection.cursor() as cursor:
cursor.execute("select job_dict from app.job", ())
column_names = [desc[0] for desc in cursor.description]
results = [dict(zip(column_names, row)) for row in
cursor.fetchall()]


The given result will have the job_dict column as string instead of
dictionary

--
Ticket URL: <https://code.djangoproject.com/ticket/33424>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 7, 2022, 11:27:07 AM1/7/22
to django-...@googlegroups.com
#33424: Jsonfield data being returned as str
-------------------------------------+-------------------------------------
Reporter: nitishxp | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:
Keywords: Database, Django | Triage Stage:
Cursor | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nitishxp):

* Attachment "Django.png" added.

Django

unread,
Jan 7, 2022, 11:27:47 AM1/7/22
to django-...@googlegroups.com
#33424: Jsonfield data being returned as str
-------------------------------------+-------------------------------------
Reporter: nitishxp | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:
Keywords: Database, Django | Triage Stage:
Cursor | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by nitishxp:

Old description:

> Hi,
>
> I encountered a bug in raw postgresql query
>
> from django.db.models import JSONField
> from django.db import connection
>
> class Job(models.Model):
> job_dict = JsonField()
>

> def view(request):
> with connection.cursor() as cursor:
> cursor.execute("select job_dict from app.job", ())
> column_names = [desc[0] for desc in cursor.description]
> results = [dict(zip(column_names, row)) for row in
> cursor.fetchall()]
>

> The given result will have the job_dict column as string instead of
> dictionary

New description:

Hi,

I encountered a bug in raw postgresql query


{{{
from django.db.models import JSONField
from django.db import connection

class Job(models.Model):
job_dict = JsonField()


def view(request):
with connection.cursor() as cursor:
cursor.execute("select job_dict from app.job", ())
column_names = [desc[0] for desc in cursor.description]
results = [dict(zip(column_names, row)) for row in
cursor.fetchall()]

}}}


The given result will have the job_dict column as string instead of
dictionary

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33424#comment:1>

Django

unread,
Jan 7, 2022, 11:35:32 AM1/7/22
to django-...@googlegroups.com
#33424: Jsonfield data being returned as str
-------------------------------------+-------------------------------------
Reporter: nitishxp | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |

Severity: Normal | Resolution:
Keywords: Database, Django | Triage Stage:
Cursor | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by nitishxp):

* component: Uncategorized => Database layer (models, ORM)


--
Ticket URL: <https://code.djangoproject.com/ticket/33424#comment:2>

Django

unread,
Jan 7, 2022, 11:45:04 AM1/7/22
to django-...@googlegroups.com
#33424: Jsonfield data being returned as str
-------------------------------------+-------------------------------------
Reporter: nitishxp | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: Database, Django | Triage Stage:
Cursor | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #31991, see
[https://code.djangoproject.com/ticket/31991#comment:1 comment] and
[https://docs.djangoproject.com/en/stable/releases/3.1.1/ 3.1.1] release
notes.

--
Ticket URL: <https://code.djangoproject.com/ticket/33424#comment:3>

Django

unread,
Jan 7, 2022, 10:35:01 PM1/7/22
to django-...@googlegroups.com
#33424: Jsonfield data being returned as str
-------------------------------------+-------------------------------------
Reporter: nitishxp | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: Database, Django | Triage Stage:
Cursor | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by nitishxp):

Replying to [comment:3 Mariusz Felisiak]:

Can you give me the example how to call json.loads() on fetched data in
case of cursor query. I am having hard time figuring this out.


Thanks

--
Ticket URL: <https://code.djangoproject.com/ticket/33424#comment:4>

Reply all
Reply to author
Forward
0 new messages