diff --git a/fauna/client/client.py b/fauna/client/client.py index d1cac5c8..4a3aea91 100644 --- a/fauna/client/client.py +++ b/fauna/client/client.py @@ -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 @@ -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 diff --git a/tests/integration/test_change_feeds.py b/tests/integration/test_change_feeds.py index 1056bd2e..51b8e306 100644 --- a/tests/integration/test_change_feeds.py +++ b/tests/integration/test_change_feeds.py @@ -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)) diff --git a/tests/integration/test_stream.py b/tests/integration/test_stream.py index 9d312fed..2eb53a59 100644 --- a/tests/integration/test_stream.py +++ b/tests/integration/test_stream.py @@ -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'})"))