Thursday, October 17, 2019

[bug] Django 2.2.6 breaks postgres orm querying for list inside a jsonfield

Assuming I have a model Like this:

    class Sequence(models.Model):
        triggers = JSONField()

Now, all my instances will be of the format:
triggers = {'list1': [], 'list2': []) 

So a query which worked in 2.2.5 Sequence.objects.filter(triggers__list1__contains=['str']) does not work in django 2.2.6.
It raises a TypeError

 {"message": "Traceback (most recent call last):   File '/code/webhooks/facebook/views.py', line 318, in post     handle_messenger_webhook(parsed_obj=parsed_obj, test=if_test)   File '/code/webhooks/facebook/views.py', line 277, in handle_messenger_webhook     sequence, serial = get_triggered_sequence_and_serial(customer=customer, payload=payload)   File '/code/webhooks/facebook/views.py', line 226, in get_triggered_sequence_and_serial     sequence = Sequence.objects.filter(platform=customer.platform, triggers__postbacks__contains=[payload]).first()   File '/usr/local/lib/python3.6/site-packages/django/db/models/query.py', line 653, in first     for obj in (self if self.ordered else self.order_by('pk'))[:1]:   File '/usr/local/lib/python3.6/site-packages/django/db/models/query.py', line 274, in __iter__     self._fetch_all()   File '/usr/local/lib/python3.6/site-packages/django/db/models/query.py', line 1242, in _fetch_all     self._result_cache = list(self._iterable_class(self))   File '/usr/local/lib/python3.6/site-packages/django/db/models/query.py', line 55, in __iter__     results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)   File '/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py', line 1087, in execute_sql     sql, params = self.as_sql()   File '/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py', line 489, in as_sql     where, w_params = self.compile(self.where) if self.where is not None else ('', [])   File '/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py', line 405, in compile     sql, params = node.as_sql(self, self.connection)   File '/usr/local/lib/python3.6/site-packages/django/db/models/sql/where.py', line 81, in as_sql     sql, params = compiler.compile(child)   File '/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py', line 405, in compile     sql, params = node.as_sql(self, self.connection)   File '/usr/local/lib/python3.6/site-packages/django/contrib/postgres/lookups.py', line 11, in as_sql     params = lhs_params + rhs_params TypeError: can only concatenate tuple (not 'list') to tuple "}

Would you bee kind enough to check it? Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4526fd33-631b-4f7d-b0b3-963856f858f9%40googlegroups.com.

No comments:

Post a Comment