﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27886	Django contrib.postgres JSONField adds additonal quotes to a dictionary.	pypetey		"I have installed django-channels and django-cq library for async/background tasks.

JSONField from django.contrib.postgres.fields is used on the model.

And when I assign to function to do async stuff the django-cq library would be creating a task in the database.

The code is relatively simple - it creates a Task object in the database and it uses JSONField  from contrib.postgres on signature field.

    sig = to_signature(func, args, kwargs)
    if parent is None and previous:
        parent = previous.parent
    task = Task.objects.create(signature={}, parent=parent, previous=previous, **kw)

When I access task objcect directly then I get 

task.__dict__
Out[2]: 
    {'_parent_cache': None,
 '_previous_cache': None,
 '_state': <django.db.models.base.ModelState at 0x83fcfd0>,
 '_uncommitted_filefields': [],
 'at_risk': 'N',
 'details': {},
 'finished': None,
 'force_chain': False,
 'id': UUID('40e62169-f743-47a1-95ea-ebe57acc9f38'),
 'last_retry': None,
 'parent_id': None,
 'previous_id': None,
 'result_expiry': None,
 'result_ttl': 1800,
 'retries': 0,
 'signature': {'args': (),
  'func_name': 'apps.accounts.consumers.send_email',
  'kwargs': {}},
 'started': None,
 'status': 'P',
 'submitted': datetime.datetime(2017, 2, 28, 13, 47, 46, 329656, tzinfo=<UTC>),
 'waiting_on_id': None}

However, when I do refresh the instsance from db by doing task.refresh_from_db() and then task.__dict__

I will receive this variation which has completely different quoting on JSONField fields (signature and details)

Out[4]: 
{'_state': <django.db.models.base.ModelState at 0x83fcfd0>,
 '_uncommitted_filefields': [],
 'at_risk': 'N',
 'details': '{}',
 'finished': None,
 'force_chain': False,
 'id': UUID('40e62169-f743-47a1-95ea-ebe57acc9f38'),
 'last_retry': None,
 'parent_id': None,
 'previous_id': None,
 'result_expiry': None,
 'result_ttl': 1800,
 'retries': 0,
 'signature': '{""args"": [], ""kwargs"": {}, ""func_name"": ""apps.accounts.consumers.send_email""}',
 'started': None,
 'status': 'P',
 'submitted': datetime.datetime(2017, 2, 28, 13, 47, 46, 329656, tzinfo=<UTC>),
 'waiting_on_id': None}


What could be root cause of the problem? Is it a bug in django?

I use windows 10 pro, postgres 95, python 3.5 32bit


This ticket might be related with:
https://code.djangoproject.com/ticket/25532#no2"	Uncategorized	new	contrib.postgres	1.10	Normal				Unreviewed	0	0	0	0	0	0
