-
Notifications
You must be signed in to change notification settings - Fork 114
Add option to set If-Match eTag for objects write requests
#205
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e55215
Add option to set `If-Match` eTag for objects write requests
445a695
Added tests and some fixes
e83787a
examples adjustment
431c499
My bad
0ad33d9
How to get http status in example
56e195f
PubNub SDK 10.2.0 release.
pubnub-release-bot 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
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import os | ||
|
|
||
| from copy import deepcopy | ||
| from pubnub.pubnub import PubNub | ||
| from pubnub.pnconfiguration import PNConfiguration | ||
| from pubnub.exceptions import PubNubException | ||
|
|
||
| config = PNConfiguration() | ||
| config.publish_key = os.getenv('PUBLISH_KEY', default='demo') | ||
| config.subscribe_key = os.getenv('SUBSCRIBE_KEY', default='demo') | ||
| config.user_id = "example" | ||
|
|
||
| config_2 = deepcopy(config) | ||
| config_2.user_id = "example_2" | ||
|
|
||
| pubnub = PubNub(config) | ||
| pubnub_2 = PubNub(config_2) | ||
|
|
||
| sample_user = { | ||
| "uuid": "SampleUser", | ||
| "name": "John Doe", | ||
| "email": "jd@example.com", | ||
| "custom": {"age": 42, "address": "123 Main St."}, | ||
| } | ||
|
|
||
| # One client creates a metada for the user "SampleUser" and successfully writes it to the server. | ||
| set_result = pubnub.set_uuid_metadata( | ||
| **sample_user, | ||
| include_custom=True, | ||
| include_status=True, | ||
| include_type=True | ||
| ).sync() | ||
|
|
||
| # We store the eTag for the user for further updates. | ||
| original_e_tag = set_result.result.data.get('eTag') | ||
|
|
||
| # Another client sets the user meta with the same UUID but different data. | ||
| overwrite_result = pubnub_2.set_uuid_metadata(uuid="SampleUser", name="Jane Doe").sync() | ||
| new_e_tag = overwrite_result.result.data.get('eTag') | ||
|
|
||
| # We can verify that there is a new eTag for the user. | ||
| print(f"{original_e_tag == new_e_tag=}") | ||
|
|
||
| # We modify the user and try to update it. | ||
| updated_user = {**sample_user, "custom": {"age": 43, "address": "321 Other St."}} | ||
|
|
||
| try: | ||
| update_result = pubnub.set_uuid_metadata( | ||
| **updated_user, | ||
| include_custom=True, | ||
| include_status=True, | ||
| include_type=True | ||
| ).if_matches_etag(original_e_tag).sync() | ||
| except PubNubException as e: | ||
| # We get an exception and after reading the error message we can see that the reason is that the eTag is outdated. | ||
| print(f"Update failed: {e.get_error_message().get('message')}\nHTTP Status Code: {e.get_status_code()}") | ||
|
|
||
|
|
||
| except Exception as e: | ||
| print(f"Unexpected error: {e}") | ||
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
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
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
Empty file.
Oops, something went wrong.
Oops, something went wrong.
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.
Do you have the possibility to check that the HTTP status code is 412?
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.
yes. added to this example