Skip to content

Commit

Permalink
examples adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Feb 7, 2025
1 parent 445a695 commit e83787a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/native_sync/using_etag.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
).sync()

# We store the eTag for the user for further updates.
e_tag = set_result.result.data.get('eTag')
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"{e_tag == new_e_tag=}")
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."}}
Expand All @@ -50,8 +50,9 @@
include_custom=True,
include_status=True,
include_type=True
).if_matches_etag(e_tag).sync()
).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')}")

except Exception as e:
print(f"Unexpected error: {e}")

0 comments on commit e83787a

Please sign in to comment.