Skip to content

Django 6.0 compatibility: as_sql() methods return list instead of tuple #271

@Freyja-Folkvangr

Description

@Freyja-Folkvangr

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 methods process_lhs() and process_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 the as_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 list

HStoreColumn.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions