Skip to content

Commit 799206c

Browse files
authored
Merge pull request #107473 from simorenoh/patch-1
[Cosmos] Python - Update how-to-manage-conflicts.md
2 parents 913dd55 + 8b897d3 commit 799206c

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

articles/cosmos-db/nosql/how-to-manage-conflicts.md

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,10 @@ const { container: lwwContainer } = await database.containers.createIfNotExists(
117117
### <a id="create-custom-conflict-resolution-policy-lww-python"></a>Python SDK
118118

119119
```python
120-
udp_collection = {
121-
'id': self.udp_collection_name,
122-
'conflictResolutionPolicy': {
123-
'mode': 'LastWriterWins',
124-
'conflictResolutionPath': '/myCustomId'
125-
}
126-
}
127-
udp_collection = self.try_create_document_collection(
128-
create_client, database, udp_collection)
120+
database = client.get_database_client(database=database_id)
121+
lww_conflict_resolution_policy = {'mode': 'LastWriterWins', 'conflictResolutionPath': '/regionId'}
122+
lww_container = database.create_container(id=lww_container_id, partition_key=PartitionKey(path="/id"),
123+
conflict_resolution_policy=lww_conflict_resolution_policy)
129124
```
130125

131126
## Create a custom conflict resolution policy using a stored procedure
@@ -314,15 +309,10 @@ After your container is created, you must create the `resolver` stored procedure
314309
### <a id="create-custom-conflict-resolution-policy-stored-proc-python"></a>Python SDK
315310

316311
```python
317-
udp_collection = {
318-
'id': self.udp_collection_name,
319-
'conflictResolutionPolicy': {
320-
'mode': 'Custom',
321-
'conflictResolutionProcedure': 'dbs/' + self.database_name + "/colls/" + self.udp_collection_name + '/sprocs/resolver'
322-
}
323-
}
324-
udp_collection = self.try_create_document_collection(
325-
create_client, database, udp_collection)
312+
database = client.get_database_client(database=database_id)
313+
udp_custom_resolution_policy = {'mode': 'Custom' }
314+
udp_container = database.create_container(id=udp_container_id, partition_key=PartitionKey(path="/id"),
315+
conflict_resolution_policy=udp_custom_resolution_policy)
326316
```
327317

328318
After your container is created, you must create the `resolver` stored procedure.
@@ -421,14 +411,10 @@ const {
421411
### <a id="create-custom-conflict-resolution-policy-python"></a>Python SDK
422412

423413
```python
424-
database = client.ReadDatabase("dbs/" + self.database_name)
425-
manual_collection = {
426-
'id': self.manual_collection_name,
427-
'conflictResolutionPolicy': {
428-
'mode': 'Custom'
429-
}
430-
}
431-
manual_collection = client.CreateContainer(database['_self'], collection)
414+
database = client.get_database_client(database=database_id)
415+
manual_resolution_policy = {'mode': 'Custom'}
416+
manual_container = database.create_container(id=manual_container_id, partition_key=PartitionKey(path="/id"),
417+
conflict_resolution_policy=manual_resolution_policy)
432418
```
433419

434420
## Read from conflict feed
@@ -509,7 +495,7 @@ const { result: conflicts } = await container.conflicts.readAll().toArray();
509495
### <a id="read-from-conflict-feed-python"></a>Python
510496

511497
```python
512-
conflicts_iterator = iter(client.ReadConflicts(self.manual_collection_link))
498+
conflicts_iterator = iter(container.list_conflicts())
513499
conflict = next(conflicts_iterator, None)
514500
while conflict:
515501
# Do something with conflict

0 commit comments

Comments
 (0)