This repository was archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Query iterator only throws exeption once #252
Merged
flyingsilverfin
merged 1 commit into
typedb:master
from
flyingsilverfin:only-store-tx-error-on-bidistream
Mar 22, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,8 @@ | |
from typing import Generic, TypeVar, Dict, Optional | ||
from uuid import UUID | ||
|
||
from typedb.common.exception import TypeDBClientException, TRANSACTION_CLOSED, ILLEGAL_STATE, \ | ||
TRANSACTION_CLOSED_WITH_ERRORS | ||
from grpc import RpcError | ||
from typedb.common.exception import TypeDBClientException, TRANSACTION_CLOSED, ILLEGAL_STATE | ||
|
||
R = TypeVar('R') | ||
|
||
|
@@ -54,26 +54,23 @@ class Queue(Generic[R]): | |
|
||
def __init__(self): | ||
self._response_queue: queue.Queue[Response] = queue.Queue() | ||
self._error: TypeDBClientException = None | ||
|
||
def get(self, block: bool) -> R: | ||
response = self._response_queue.get(block=block) | ||
if response.is_value(): | ||
return response.value | ||
elif response.is_done(): | ||
self._raise_transaction_closed_error() | ||
elif response.is_done() and response.error is None: | ||
raise TypeDBClientException.of(TRANSACTION_CLOSED) | ||
elif response.is_done() and response.error is not None: | ||
raise TypeDBClientException.of_rpc(response.error) | ||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go back to the old behaviour of retrieving the error from the |
||
else: | ||
raise TypeDBClientException.of(ILLEGAL_STATE) | ||
|
||
def _raise_transaction_closed_error(self): | ||
raise TypeDBClientException.of(TRANSACTION_CLOSED_WITH_ERRORS, self._error) if self._error else TypeDBClientException.of(TRANSACTION_CLOSED) | ||
|
||
def put(self, response: R): | ||
self._response_queue.put(ValueResponse(response)) | ||
|
||
def close(self, error: Optional[TypeDBClientException]): | ||
self._error = error | ||
self._response_queue.put(DoneResponse()) | ||
self._response_queue.put(DoneResponse(error)) | ||
|
||
|
||
class Response: | ||
|
@@ -96,8 +93,8 @@ def is_value(self): | |
|
||
class DoneResponse(Response): | ||
|
||
def __init__(self): | ||
pass | ||
def __init__(self, error: Optional[RpcError]): | ||
self.error = error | ||
|
||
def is_done(self): | ||
return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,9 +74,7 @@ def _has_next(self) -> bool: | |
raise TypeDBClientException.of(ILLEGAL_STATE) | ||
|
||
def __next__(self) -> transaction_proto.Transaction.ResPart: | ||
if self._bidirectional_stream.get_error() is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the error will come from the backing |
||
raise self._bidirectional_stream.get_error() | ||
elif not self._has_next(): | ||
if not self._has_next(): | ||
raise StopIteration | ||
else: | ||
self._state = ResponsePartIterator.State.EMPTY | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline var