For versions earlier than 0.8.0 the model classes for document types:
DocumentDesignDocumentReplicationDocument
were generated with standard Python convention names for all fields.
By convention a leading _ in Python implies internal use so leading _ were
not used for the reserved CouchDB names in the Python model classes and
were added during serialization.
This representation of the Document model did not allow for members with the
same names as the reserved (_ prefixed) document metadata members.
This meant that members named any of the following were removed by the Document
from_dict and to_dict functions:
attachmentsconflictsdeleteddeleted_conflictsidlocal_seqrevrevisionsrevs_info
as described in issue #490.
To resolve this problem, starting from version 0.8.0 model classes that accept
user defined properties use the leading _ CouchDB convention for
CouchDB metadata property names instead of using the Python convention.
This introduces breaking changes that require code updates for usages
of the model types Document, DesignDocument and ReplicationDocument.
The kwarg or attribute names that changed are:
kwarg/attribute name (<0.8.0) |
kwarg/attribute name (>=0.8.0) |
|---|---|
attachments |
_attachments |
conflicts |
_conflicts |
deleted |
_deleted |
deleted_conflicts |
_deleted_conflicts |
id |
_id |
local_seq |
_local_seq |
rev |
_rev |
revisions |
_revisions |
revs_info |
_revs_info |
Note: Dictionary literals always used the _ prefixed form of the
name so there are no code changes in those cases.
In the case of writing to the server the names are kwarg parameters used to initialize these classes:
DocumentDesignDocumentReplicationDocument
The functions that impacted by these changes are:
- Functions that accept
Documentin thedocumentkwarg:post_documentput_documentput_local_document
- Functions that accept
DesignDocumentin thedesign_documentkwarg:put_design_document
- Functions that accept
ReplicationDocumentin thereplication_documentkwarg:put_replication_document
- Functions that accept
BulkDocsin thebulk_docskwarg. In this case the changes are in the elements of theList[Document]in thedocskwarg:post_bulk_docs
Before:
# id is used in Document initializer
my_doc = Document(
id="small-appliances:1000042",
type="product",
productid="1000042",
name="Fidget toy")
result = service.post_document(db='products', document=my_doc).get_result()After:
# Now _id is used in Document initializer
my_doc = Document(
_id="small-appliances:1000042",
type="product",
productid="1000042",
name="Fidget toy")
result = service.post_document(db='products', document=my_doc).get_result()Before & After (no changes):
# _id is used in dict literal
my_doc = {
'_id': 'small-appliances:1000042',
'type': 'product',
'productid': '1000042',
'name': 'Fidget toy'
}
result = service.post_document(db='products', document=my_doc).get_result()In the case of reading from the server the _ prefixed names were always used in the raw
dictionaries returned from the get_result function. As such no changes are necessary
to the key names to read the values from these result dicts. However, renames are necessary
if the calling code uses the from_dict function to convert the result dict to a model class.
The functions impacted in that case are:
- Functions returning a
dictthat represents aDocument:get_documentget_local_document
- Functions returning a
dictthat represents aDesignDocument:get_design_document
- Functions returning a
dictthat represents aReplicationDocument:get_replication_document
- Functions returning a
dictcontaining aDocumentrepresentation:post_bulk_get(viaBulkGetResultresults>BulkGetResultItemdocs>BulkGetResultDocumentok)
- Functions returning a
dictpotentially containing aDocumentrepresentation (for example if usinginclude_docs):post_all_docs(viaAllDocsResultrows>DocsResultRowdoc)post_changes(viaChangesResultresults>ChangesResultItemdoc)post_find(viaFindResultdocs)post_partition_find(viaFindResultdocs)post_search(viaSearchResultrows>SearchResultRowdocorSearchResultgroups>SearchResultPropertiesrows>SearchResultRowdoc)post_partition_search(viaSearchResultrows>SearchResultRowdocorSearchResultgroups>SearchResultPropertiesrows>SearchResultRowdoc)post_view(viaViewResultrows>ViewResultRowdoc)post_partition_view(viaViewResultrows>ViewResultRowdoc)
Before & after (no changes):
result = service.get_document(
db='products',
doc_id='small-appliances:1000042'
).get_result()
# _id is used to access document id in result dict
print(result._id)
# prints:
# small-appliances:1000042Before:
result = service.get_document(
db='products',
doc_id='small-appliances:1000042'
).get_result()
doc = Document.from_dict(result)
# id is used to access document id in Document class
print(doc.id)
# prints:
# small-appliances:1000042After:
result = service.get_document(
db='products',
doc_id='small-appliances:1000042'
).get_result()
doc = Document.from_dict(result)
# Now _id is used to access document id in Document class
print(doc._id)
# prints:
# small-appliances:1000042