#31973: TypeError loading data in JSONField if DB has native JSON support
-------------------------------------+-------------------------------------
     Reporter:  Adam Alton           |                    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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

 Replying to [comment:19 giacomo]:
 > I'm also experiencing this error on Django >= 3.1.1 when using
 `jsonb_array_length` on a `JSONField` that contains a list:
 >
 > {{{
 > class MyModel(models.Model):
 >     field = JSONField(default=list)
 >
 > >>> MyModel.objects.annotate(field_len=Func(F('field'),
 function='jsonb_array_length'))

 Do you really want to get `JSON` as a result of `JSONB_ARRAY_LENGTH()`? I
 think you missed `output_field`, e.g.
 {{{
 MyModel.objects.annotate(field_len=Func(F('field'),
 function='jsonb_array_length', output_field=IntegerField()))
 }}}
 works fine.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31973#comment:20>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.cbf602771a8d184a04b4e2997b5af102%40djangoproject.com.

Reply via email to