Skip to content

Commit

Permalink
[FE-5985] Error when configuring start_ts and cursor at the same time (
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson authored Oct 10, 2024
1 parent 38b6d5b commit 4d25b58
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fauna/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ def __init__(self, http_client: HTTPClient, headers: Dict[str, str],
self.last_cursor = None
self._ctx = self._create_stream()

if opts.start_ts is not None and opts.cursor is not None:
err_msg = "Only one of 'start_ts' or 'cursor' can be defined in the StreamOptions."
raise TypeError(err_msg)

def __enter__(self):
return self

Expand Down Expand Up @@ -671,6 +675,10 @@ def __init__(self, http: HTTPClient, headers: Dict[str, str], endpoint: str,
self._request: Dict[str, Any] = {"token": token.token}
self._is_done = False

if opts.start_ts is not None and opts.cursor is not None:
err_msg = "Only one of 'start_ts' or 'cursor' can be defined in the ChangeFeedOptions."
raise TypeError(err_msg)

if opts.page_size is not None:
self._request["page_size"] = opts.page_size

Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_change_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ def test_change_feed_cursor(client, a_collection):
assert nums == list(range(1, 64))


def test_rejects_when_both_start_ts_and_cursor_provided(scoped_client):
scoped_client.query(fql("Collection.create({name: 'Product'})"))

response = scoped_client.query(fql("Product.all().toStream()"))
stream_token = response.data

with pytest.raises(TypeError):
opts = ChangeFeedOptions(cursor="abc1234==", start_ts=response.txn_ts)
scoped_client.change_feed(stream_token, opts)


def test_change_feed_reusable_iterator(client, a_collection):
feed = client.change_feed(
fql("${col}.all().map(.n).toStream()", col=a_collection))
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ def test_rejects_cursor_with_fql_query(scoped_client):
scoped_client.stream(fql("Collection.create({name: 'Product'})"), opts)


def test_rejects_when_both_start_ts_and_cursor_provided(scoped_client):
scoped_client.query(fql("Collection.create({name: 'Product'})"))

response = scoped_client.query(fql("Product.all().toStream()"))
stream_token = response.data

with pytest.raises(TypeError):
opts = StreamOptions(cursor="abc1234==", start_ts=response.txn_ts)
scoped_client.stream(stream_token, opts)


def test_handle_status_events(scoped_client):
scoped_client.query(fql("Collection.create({name: 'Product'})"))

Expand Down

0 comments on commit 4d25b58

Please sign in to comment.