votes up 3

Invalid connector for timedelta: %s.

Package:
django
github stars 59414
Exception Class:
DatabaseError

Raise code

            return 'POWER(%s)' % ','.join(sub_expressions)
        elif connector == '#':
            return 'BITXOR(%s)' % ','.join(sub_expressions)
        return super().combine_expression(connector, sub_expressions)

    def combine_duration_expression(self, connector, sub_expressions):
        if connector not in ['+', '-', '*', '/']:
            raise DatabaseError('Invalid connector for timedelta: %s.' % connector)
        fn_params = ["'%s'" % connector] + sub_expressions
        if len(fn_params) > 3:
            raise ValueError('Too many params for timedelta operations.')
        return "django_format_dtdelta(%s)" % ', '.join(fn_params)

    def integer_field_range(self, internal_type):
        # SQLite doesn't enforce any integer constraints
🙏 Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 2 votes down

Summary: Only certain connectors are supported on deltatime

The latest Django version 3.2.4 tag only support "+" and "-". If other connectors are used, will get the exception

https://github.com/django/django/blob/843c34b3ab921c1acf77ee2014a97bc7975595b8/django/db/backends/sqlite3/operations.py#L344

However in the "main" branch of Django supports "+", "-", "*", and "/". If other connectors are used, will get the exception

https://github.com/django/django/blob/ecf8af79355c8daa67722bd0de946b351f7f613d/django/db/backends/sqlite3/operations.py#L354

Code to reproduce (WRONG): Django version 3.2.4 will not work, but "main" branch will work

from django.db.backends.sqlite3.operations import DatabaseOperations

operations =  DatabaseOperations(connection=None)
operations.combine_duration_expression(connector='*', sub_expressions=['expression'])

Working version (Fixed): Works for both Django version 3.2.4 and "main" branch

from django.db.backends.sqlite3.operations import DatabaseOperations

operations =  DatabaseOperations(connection=None)
operations.combine_duration_expression(connector='+', sub_expressions=['expression'])
Jun 06, 2021 phoang88 answer
phoang88 615

Add a possible fix

Please authorize to post fix