3

I need to filter some objects that have no specific value in the field. I tried to do it like this:

MyModel.objects\
    .filter(<some filters>)\
    .exclude(json_field__has_key='some_field', json_field__some_field=True)

But this code generates wrong SQL query:

... 
AND NOT (
    "my_model"."json_field" ? some_field AND
    ("my_model"."json_field" -> 'some_field') = 'true' AND
    "my_model"."json_field" IS NOT NULL)
)
...

On the first line some_field used without qoutes. I fixed it by adding single qoutes to the string like this: json_field__has_key="'some_field'" but I dont think it's a good solution.

Does anyone have an idea why it works this way and how I should fix it?

1 Answers1

0

Well, my bad... I just logged my queries as queryset.query that has really wrong representation of the SQL query. When I logged real queries using connector I saw correct query (see this answer for more details).