Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33424 closed Bug (duplicate)

Jsonfield data being returned as str

Reported by: nitishxp Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords: Database, Django Cursor
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by nitishxp)

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

Attachments (1)

Django.png (37.2 KB ) - added by nitishxp 3 years ago.

Download all attachments as: .zip

Change History (5)

by nitishxp, 3 years ago

Attachment: Django.png added

comment:1 by nitishxp, 3 years ago

Description: modified (diff)

comment:2 by nitishxp, 3 years ago

Component: UncategorizedDatabase layer (models, ORM)

comment:3 by Mariusz Felisiak, 3 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #31991, see comment and 3.1.1 release notes.

in reply to:  3 comment:4 by nitishxp, 3 years ago

Replying to Mariusz Felisiak:

Duplicate of #31991, see comment and 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

Note: See TracTickets for help on using tickets.
Back to Top