Skip to content

Commit

Permalink
django: fix power operator (^)
Browse files Browse the repository at this point in the history
The tests remain commented out because issue #331 also affects them.

fixes #333
  • Loading branch information
timgraham committed Mar 18, 2020
1 parent 8018a3f commit d940e47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django_spanner/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ class DatabaseFeatures(BaseDatabaseFeatures):
# https://github.com/orijtech/django-spanner/issues/331
'expressions.tests.ExpressionOperatorTests.test_lefthand_division',
'expressions.tests.ExpressionOperatorTests.test_right_hand_division',
# power operator doesn't work:
# https://github.com/orijtech/django-spanner/issues/333
# power operator produces a float result, which can't be assigned to
# an integer column:
# https://github.com/orijtech/django-spanner/issues/331
'expressions.tests.ExpressionOperatorTests.test_lefthand_power',
'expressions.tests.ExpressionOperatorTests.test_righthand_power',
# Cloud Spanner's docs: "The rows that are returned by LIMIT and OFFSET
Expand Down
2 changes: 2 additions & 0 deletions django_spanner/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def format_for_duration_arithmetic(self, sql):
def combine_expression(self, connector, sub_expressions):
if connector == '%%':
return 'MOD(%s)' % ', '.join(sub_expressions)
elif connector == '^':
return 'POWER(%s)' % ', '.join(sub_expressions)
return super().combine_expression(connector, sub_expressions)

def combine_duration_expression(self, connector, sub_expressions):
Expand Down

0 comments on commit d940e47

Please sign in to comment.