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

Merge pr 35022 into pr34694 - Add Start Time To CF, Fix Retryable Exception in First Page Bug, and Fix Case Sensitive Headers Bug #35090

Merged
merged 27 commits into from
Apr 11, 2024

Conversation

bambriz
Copy link
Member

@bambriz bambriz commented Apr 5, 2024

Description

Original PR 35022
This removes merge conflicts with PR 34694

PR 35022 had an infinite loop issue with queries. Infinite Loop was removed while keeping the fix to the retryable exception bug in the first page of a query. This PR also adds Start Time option in change feed pulls, and fixes a bug where response headers were being returned and used as Case Sensitive Dictionaries. Response Headers are now Case Insensitive Multi Dictionaries.

A utc datetime is passed into the options when calling a change feed pull. If the datetime is not utc it will be converted to utc.

The following Example creates 10 items at two different times. By using start time you can filter out the items created after the time recorded.

    batchSize = 10
    container = database.get_container_client(container_name)
    create_random_items(container, batchSize)
    sleep(1)
    now = datetime.now(timezone.utc)
    sleep(1)
    create_random_items(container, batchSize)
    change_feed_iter = container.query_items_change_feed(start_time=now)

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

bambriz and others added 13 commits March 7, 2024 13:34
Adds start time, at the moment has a work around for getting all the documents.
Start time change feed queries always result in the initial fetch results being empty, which is a deviation in behaviour from other change feed options. To accommodate that we check if we have the start time change feed option and check if it is the first fetch request in order to grab the continuation value from etag to get the rest of the results.
Added a new header to remove ambuiguity between 'etag' meant for sync clients and 'Etag' meant for async clients in our code for header strings.
added negative test for start time option of change feed.
…ged prs

Response headers are now CIMultDict type (Case insensitive Multi Dictionaries) which fixes any issues regarding casing of header strings. This also has changes to merge changes from PR 35022 without issues.
This code checks if a 429 error has occured in which case we reset has started and try getting the fetch items again
@github-actions github-actions bot added the Cosmos label Apr 5, 2024
@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-cosmos

bambriz added 4 commits April 5, 2024 16:13
Added code to help debug. This will catch 429 exception when it occurs on first page of query so we can see whats going on.
Moving the has_Started flag to after the fetch function seems to make the behaviour better align with what is expected. Retries are properly done for queries that got 429 in the first page of their query, and 429s are also being properly surfaced when retries runout.
Remove trailing spaces, bad indentation, and unused imports
@bambriz
Copy link
Member Author

bambriz commented Apr 8, 2024

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bambriz bambriz changed the title Merge pr 35022 into pr34694 Merge pr 35022 into pr34694 - Add Start Time To CF, Fix Retryable Exception in First Page Bug, and Fix Case Sensitive Headers Bug Apr 8, 2024
@bambriz bambriz marked this pull request as ready for review April 8, 2024 20:37
@bambriz bambriz requested a review from annatisch as a code owner April 8, 2024 20:37
sdk/cosmos/azure-cosmos/azure/cosmos/_base.py Outdated Show resolved Hide resolved
@simorenoh
Copy link
Member

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

This push adds test coverage for the retryable exception bug that this PR fixes. It recreates the scenario of the original bug and verifies that the fix is working. This also changes the start time datetime to always be converted to UTC regardless of timezone or if it is a naive datetime.
@bambriz
Copy link
Member Author

bambriz commented Apr 10, 2024

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@simorenoh simorenoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work Bryan, thanks!

Fixed outdated comments to better match new code.
Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @bambriz, thanks for fixing the other bugs as well. Added some comments, and requesting changes for samples on start time usage in change feed query.

sdk/cosmos/azure-cosmos/CHANGELOG.md Outdated Show resolved Hide resolved
sdk/cosmos/azure-cosmos/CHANGELOG.md Outdated Show resolved Hide resolved
sdk/cosmos/azure-cosmos/CHANGELOG.md Outdated Show resolved Hide resolved
sdk/cosmos/azure-cosmos/azure/cosmos/_base.py Outdated Show resolved Hide resolved
bambriz and others added 4 commits April 10, 2024 14:49
Co-authored-by: Kushagra Thapar <kushuthapar@gmail.com>
Co-authored-by: Kushagra Thapar <kushuthapar@gmail.com>
Co-authored-by: Kushagra Thapar <kushuthapar@gmail.com>
Added further optimizations.
@bambriz
Copy link
Member Author

bambriz commented Apr 10, 2024

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

pylint fixes
@bambriz
Copy link
Member Author

bambriz commented Apr 10, 2024

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @bambriz
Please also add the sample for using start from time functionality :)

Add samples for start time change feed
@bambriz
Copy link
Member Author

bambriz commented Apr 11, 2024

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -342,6 +345,8 @@ def query_items_change_feed(
feed_options["partitionKey"] = self._set_partition_key(partition_key)
if is_start_from_beginning is not None:
feed_options["isStartFromBeginning"] = is_start_from_beginning
if start_time is not None and is_start_from_beginning is False and isinstance(start_time, datetime):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check isn't correct - we should not be doing an isinstance check for start_time - because this will fail silently if they pass in something else. We should just let it fail if they pass in the wrong type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants