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.
* Attachment "Django.png" added.
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>
* component: Uncategorized => Database layer (models, ORM)
--
Ticket URL: <https://code.djangoproject.com/ticket/33424#comment:2>
* 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>
Comment (by nitishxp):
Replying to [comment:3 Mariusz Felisiak]:
> 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.
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>