Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE-5985] Error when configuring start_ts and cursor at the same time #199

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading