@@ -441,41 +441,45 @@ multiple updates to a single document. Note that we don't save to the server
441441after each update. We only save once to the server upon exiting the ``Document ``
442442context manager.
443443
444- .. code-block :: python
444+ .. warning :: Uncaught exceptions inside the ``with`` block will prevent your
445+ document changes being saved to the remote server. However, changes
446+ will still be applied to your local document object.
445447
446- from cloudant import cloudant
447- from cloudant.document import Document
448+ .. code-block :: python
448449
449- with cloudant(USERNAME , PASSWORD , account = ACCOUNT_NAME ) as client:
450+ from cloudant import cloudant
451+ from cloudant.document import Document
450452
451- my_database = client.create_database( ' my_database ' )
453+ with cloudant( USERNAME , PASSWORD , account = ACCOUNT_NAME ) as client:
452454
453- # Upon entry into the document context, fetches the document from the
454- # remote database, if it exists. Upon exit from the context, saves the
455- # document to the remote database with changes made within the context
456- # or creates a new document.
457- with Document(database, ' julia006' ) as document:
458- # If document exists, it's fetched from the remote database
459- # Changes are made locally
460- document[' name' ] = ' Julia'
461- document[' age' ] = 6
462- # The document is saved to the remote database
463-
464- # Display a Document
465- print (my_database[' julia30' ])
466-
467- # Delete the database
468- client.delete_database(' my_database' )
455+ my_database = client.create_database(' my_database' )
469456
470- print (' Databases: {0} ' .format(client.all_dbs()))
457+ # Upon entry into the document context, fetches the document from the
458+ # remote database, if it exists. Upon exit from the context, saves the
459+ # document to the remote database with changes made within the context
460+ # or creates a new document.
461+ with Document(database, ' julia006' ) as document:
462+ # If document exists, it's fetched from the remote database
463+ # Changes are made locally
464+ document[' name' ] = ' Julia'
465+ document[' age' ] = 6
466+ # The document is saved to the remote database
467+
468+ # Display a Document
469+ print (my_database[' julia30' ])
470+
471+ # Delete the database
472+ client.delete_database(' my_database' )
473+
474+ print (' Databases: {0} ' .format(client.all_dbs()))
471475
472476 Always use the ``_deleted `` document property to delete a document from within
473477a ``Document `` context manager. For example:
474478
475- .. code-block :: python
479+ .. code-block :: python
476480
477- with Document(my_database, ' julia30' ) as doc:
478- doc[' _deleted' ] = True
481+ with Document(my_database, ' julia30' ) as doc:
482+ doc[' _deleted' ] = True
479483
480484 *You can also delete non underscore prefixed document keys to reduce the size of the request. *
481485
0 commit comments