#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 )
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)
Change History (5)
by , 3 years ago
Attachment: | Django.png added |
---|
comment:1 by , 3 years ago
Description: | modified (diff) |
---|
comment:2 by , 3 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|
follow-up: 4 comment:3 by , 3 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:4 by , 3 years ago
Replying to 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
Note:
See TracTickets
for help on using tickets.
Duplicate of #31991, see comment and 3.1.1 release notes.