Thought I’d run this past folks…
While looking at the ORM code for this question on the old ML I realised that if people wanted to use psycopg Jsonb types directly, it appears as though Django just needs to return the value during DatabaseOperations.adapt_json_value()
:
Study.objects.filter(data__program_name__in=[Jsonb("Program1"), Jsonb("Program2")])
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -353,6 +353,8 @@ class DatabaseOperations(BaseDatabaseOperations):
return None
def adapt_json_value(self, value, encoder):
+ if type(value) == Jsonb:
+ return value
return Jsonb(value, dumps=get_json_dumps(encoder))
def subtract_temporals(self, internal_type, lhs, rhs):