#32079: Using JSONField with Func() crash when returns boolean.
-------------------------------------+-------------------------------------
     Reporter:  Loic Quertenmont     |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Thanks for this report. It works in Django < 3.1.1 but not intentionally.
 `Func()` guesses an output type based on `expressions` types, in this case
 `JSONField`, PostgreSQL supports primitives in `jsonb` data type so it
 treats the result of `jsonb_path_exists()` as a `JSONField`. As a
 consequence of #31956, fetching a `JSONField` should return a string
 instead of pre-loaded data that's why it crashes.

 I don't think there is anything to fix here, you want to use
 `jsonb_path_exists()` which takes JSON and returns boolean, so passing
 `output_field=models.BooleanField()` should be necessary.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32079#comment:1>
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/069.b5607a3eba7a5db405af96827af4669f%40djangoproject.com.

Reply via email to