Skip to content

Signature for various "operations" incompatible with Django >= 4.1 #171

Open
@anentropic

Description

@anentropic

trying to use db functions like from django.db.models.functions Trunc fails due to change in signature in Django 4.1

Problem

I have a Django 5.1 project using Trunc

Trying to use django-redshift backend fails with:

        elif isinstance(self.output_field, DateField):
>           sql, params = connection.ops.date_trunc_sql(
                self.kind, sql, tuple(params), tzname
E               TypeError: DatabaseOperations.date_trunc_sql() takes from 3 to 4 positional arguments but 5 were given

.venv/lib/python3.11/site-packages/django/db/models/functions/datetime.py:271: TypeError

signature of date_trunc_sql and many other functions changed in Django 4.1, to add params arg https://github.com/django/django/blob/4.1/django/db/backends/base/operations.py#L113

making it incompatible with the Django 4.0 code in this project here:

def date_trunc_sql(self, lookup_type, field_name, tzname=None):

DATE_TRUNC itself is supported in Redshift https://docs.aws.amazon.com/redshift/latest/dg/r_DATE_TRUNC.html the problem is just in the Django layer

Expected results

Badges advertise support for Django 4.2, 5.0, 5.1

But I understand that compatibility with Django > 4.0 is tenuous due to needing to use Django 4.0 code, due to needing to use psycopg2 lib for connecting to Redshift, as psycopg3 has issues.

Environment info

  • OS: macOS 14.6.1
  • Python version: 3.11
  • Django version: 5.1
  • Django-Redshift-Backend version: latest

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