Opened 8 years ago
Last modified 8 years ago
#27886 closed Bug
Django contrib.postgres JSONField adds additonal quotes to a dictionary. — at Version 2
Reported by: | pypetey | Owned by: | |
---|---|---|---|
Component: | contrib.postgres | Version: | 1.10 |
Severity: | Normal | Keywords: | |
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 )
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 instance 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
#25532 might be related.
Change History (2)
comment:1 by , 8 years ago
Type: | Uncategorized → Bug |
---|
comment:2 by , 8 years ago
Description: | modified (diff) |
---|