#32491: Updating a field based on a JSONField's sub-value adds extra quotes
[postgres]
-------------------------------------+-------------------------------------
               Reporter:  Baptiste   |          Owner:  nobody
  Mispelon                           |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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`

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32491>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.07fa76dd0643f749a6f1871abb5a5690%40djangoproject.com.

Reply via email to