-
Notifications
You must be signed in to change notification settings - Fork 108
Description
Problem
Django 6.0 introduced a breaking change requiring as_sql() methods to return params as a tuple, not a list.
From Django 6.0 Release Notes:
Prior to Django 6.0, custom lookups and custom expressions implementing the
as_sql()method (and its supporting methodsprocess_lhs()andprocess_rhs()) were allowed to return a sequence of params in either a list or a tuple. To address the interoperability problems that resulted, the second return element of theas_sql()method should now be a tuple.
Current Behavior
In psqlextra/expressions.py, several as_sql() methods return lists:
HStoreValue.as_sql (line 61)
return " || ".join(sql), params # params is a listHStoreColumn.as_sql (line 106)
return (
"%s.%s->'%s'"
% (qn(self.alias), qn(self.target.column), self.hstore_key),
[], # returns empty list
)Note: ExcludedCol.as_sql (line 223) correctly uses tuple().
Error
When using LocalizedField (from django-localized-fields) with Django 6.0:
psycopg2.ProgrammingError: can't adapt type 'dict'
This occurs during ORM operations that trigger HStore field handling.
Expected Behavior
All as_sql() methods should return params as tuple:
# HStoreValue.as_sql
return " || ".join(sql), tuple(params)
# HStoreColumn.as_sql
return (..., ())Environment
- Django 6.0
- django-postgres-extra: 2.0.4, 2.0.9, 3.0.0rc1 (all affected)
- Python 3.12
Related
- Issue Django 5.0 support #232 (Django 5.0 support)
- Django 6.0 Release Notes - as_sql() change