8000 django: duration arithmetic fails with dates · Issue #253 · googleapis/python-spanner-django · GitHub
[go: up one dir, main page]

Skip to content
django: duration arithmetic fails with dates #253
Closed
@timgraham

Description

@timgraham

In #209, I made the assumption that DatabaseOperations.combine_duration_expression() operates on TIMESTAMP (TIMESTAMP_ADD and TIMESTAMP_SUB). However, it can also receive a DATE in which case, Spanner crashes as it requires using DATE_ADD / DATE_SUB instead:

======================================================================
ERROR: test_date_minus_duration (expressions.tests.FTimeDeltaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/.virtualenvs/django37/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 79, in next
    return six.next(self._wrapped)
  File "/home/tim/.virtualenvs/django37/lib/python3.7/site-packages/grpc/_channel.py", line 392, in __next__
    return self._next()
  File "/home/tim/.virtualenvs/django37/lib/python3.7/site-packages/grpc/_channel.py", line 561, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
	status = StatusCode.INVALID_ARGUMENT
	details = "No matching signature for function TIMESTAMP_SUB for argument types: DATE, INTERVAL INT64 DATE_TIME_PART. Supported signature: TIMESTAMP_SUB(TIMESTAMP, INTERVAL INT64 DATE_TIME_PART) [at 1:299]\n...WHERE expressions_ExPeRiMeNt.assigned < ((TIMESTAMP_SUB(expressions_ExPeRi...\n                                             ^"
	debug_error_string = "{"created":"@1576629822.749570417","description":"Error received from peer ipv4:172.217.12.138:443","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"No matching signature for function TIMESTAMP_SUB for argument types: DATE, INTERVAL INT64 DATE_TIME_PART. Supported signature: TIMESTAMP_SUB(TIMESTAMP, INTERVAL INT64 DATE_TIME_PART) [at 1:299]\n...WHERE expressions_ExPeRiMeNt.assigned < ((TIMESTAMP_SUB(expressions_ExPeRi...\n                                             ^","grpc_status":3}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tim/code/django/tests/expressions/tests.py", line 1369, in test_date_minus_duration
    self.assertQuerysetEqual(more_than_4_days, ['e3', 'e4', 'e5'], lambda e: e.name)
  File "/home/tim/code/django/django/test/testcases.py", line 1047, in assertQuerysetEqual
    items = map(transform, qs)
  File "/home/tim/code/django/django/db/models/query.py", line 274, in __iter__
    self._fetch_all()
  File "/home/tim/code/django/django/db/models/query.py", line 1242, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/tim/code/django/django/db/models/query.py", line 55, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/home/tim/code/django/django/db/models/sql/compiler.py", line 1166, in execute_sql
    return list(result)
  File "/home/tim/code/django/django/db/models/sql/compiler.py", line 1545, in cursor_iter
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/home/tim/code/django/django/db/models/sql/compiler.py", line 1545, in <lambda>
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/home/tim/code/django/django/db/utils.py", line 96, in inner
    return func(*args, **kwargs)
  File "/home/tim/code/spanner-orm/spanner/dbapi/cursor.py", line 250, in fetchmany
    items.append(tuple(self.__next__()))
  File "/home/tim/code/spanner-orm/spanner/dbapi/cursor.py", line 213, in __next__
    return next(self.__itr)
  File "/home/tim/.virtualenvs/django37/lib/python3.7/site-packages/google/cloud/spanner_v1/streamed.py", line 143, in __iter__
    self._consume_next()
  File "/home/tim/.virtualenvs/django37/lib/python3.7/site-packages/google/cloud/spanner_v1/streamed.py", line 116, in _consume_next
    response = six.next(self._response_iterator)
  File "/home/tim/.virtualenvs/django37/lib/python3.7/site-packages/google/cloud/spanner_v1/snapshot.py", line 45, in _restart_on_unavailable
    for item in iterator:
  File "/home/tim/.virtualenvs/django37/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 81, in next
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.InvalidArgument: 400 No matching signature for function TIMESTAMP_SUB for argument types: DATE, INTERVAL INT64 DATE_TIME_PART. Supported signature: TIMESTAMP_SUB(TIMESTAMP, INTERVAL INT64 DATE_TIME_PART) [at 1:299]\n...WHERE expressions_ExPeRiMeNt.assigned < ((TIMESTAMP_SUB(expressions_ExPeRi...\n                                             ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: spannerIssues related to the googleapis/python-spanner-django API.blockedIssues that cannot be implemented because of some limitdjango-test-suitepriority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.we-cannot-typecheck-spanner-columnswontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0