Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date_trunc_sql() takes 3 positional arguments but 4 were given #118

Open
brucegibbins opened this issue Jun 15, 2021 · 1 comment
Open

Comments

@brucegibbins
Copy link

brucegibbins commented Jun 15, 2021

Hi.

Platform: Windows
Python v3.9.5
Django v3.2.4
django-mssql-backend v2.8.1
pyodbc v4.0.30

This is a new upgraded environment after moving from a functional Python v3.6.x and Django v.2.1.7 which was using django-pyodbc-azure v2.1.0

It seems that if I have a ModelAdmin Class that uses the date_hierarchy attribute then we will get the error at line 204 in

\Lib\site-packages\django\db\models\functions\datetime.py", line 204

Other details that maybe of relevance are that:-

The database field type is date and not datetime

The django debug dump indicates tzname is None and the connection object is sql_server.pyodbc.base.DatabaseWrapper

I hope this is enough detail. Please advise if I can add any extra info.

Thank-you in advance

@ajhobden
Copy link

ajhobden commented Feb 8, 2023

I've just come across this issue too.

It looks like the definition for date_trunc_sql has changed to include an optional named argument for the time zone.
old:
def date_trunc_sql(self, lookup_type, field_name)
new:
def date_trunc_sql(self, lookup_type, field_name, tzname=None)

Since there already exists code to incude the time zone this could be fixed by updating the function definition and adding an if statement to use that value if given.

    def date_trunc_sql(self, lookup_type, field_name, tzname=None):
        if tzname:
            field_name = self._convert_field_to_tz(field_name, tzname)
        CONVERT_YEAR = 'CONVERT(varchar, DATEPART(year, %s))' % field_name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants