﻿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
32491	Updating a field based on a JSONField's sub-value adds extra quotes [postgres]	Baptiste Mispelon	YashRaj1506	"Consider the following model:
{{{#!py
class JSONNamedModel(models.Model):
    name = models.CharField(max_length=10, blank=True)
    data = models.JSONField()
}}}

The following testcase seems to pass under sqlite but fails under postgres (postgresql version 13.1, psycopg2 version 2.8.6). I haven't tested other backends:
{{{#!py
class ReproductionTestCase(TestCase):
    def test_issue_update(self):
        JSONNamedModel.objects.create(data={'name': 'django'})
        JSONNamedModel.objects.update(name=F('data__name'))
        self.assertQuerysetEqual(
            JSONNamedModel.objects.all(),
            ['django'],
            transform=lambda m: m.name,
        )
}}}

To summarize what happens in the test, if you have an instance with `data={'name': 'django'}` and you do `update(name=F('data__name'))`, you end up with an instance that has `name='""django""'` (the original name with extra double quotes around it).

Interestingly, if you start with `django""`, you end up with `""django\""""` (the original `""` is backslash-escaped and the whole thing is wrapped by double quotes).


Not sure how relevant this is, but while digging into this issue I noticed that the test failure changed somewhat recently (bisected down to commit 8b040e3cbbb2e81420e777afc3ca48a1c8f4dd5a).
Before that commit, the error was `django.core.exceptions.FieldError: Joined field references are not permitted in this query`"	Bug	assigned	Database layer (models, ORM)	dev	Normal			Giannis Terzopoulos	Accepted	0	0	0	0	0	0
