For versions earlier than 0.8.0
the model classes for document types:
Document
DesignDocument
ReplicationDocument
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:
attachments
conflicts
deleted
deleted_conflicts
id
local_seq
rev
revisions
revs_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:
Document
DesignDocument
ReplicationDocument
The functions that impacted by these changes are:
- Functions that accept
Document
in thedocument
kwarg:post_document
put_document
put_local_document
- Functions that accept
DesignDocument
in thedesign_document
kwarg:put_design_document
- Functions that accept
ReplicationDocument
in thereplication_document
kwarg:put_replication_document
- Functions that accept
BulkDocs
in thebulk_docs
kwarg. In this case the changes are in the elements of theList[Document]
in thedocs
kwarg: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
dict
that represents aDocument
:get_document
get_local_document
- Functions returning a
dict
that represents aDesignDocument
:get_design_document
- Functions returning a
dict
that represents aReplicationDocument
:get_replication_document
- Functions returning a
dict
containing aDocument
representation:post_bulk_get
(viaBulkGetResult
results
>BulkGetResultItem
docs
>BulkGetResultDocument
ok
)
- Functions returning a
dict
potentially containing aDocument
representation (for example if usinginclude_docs
):post_all_docs
(viaAllDocsResult
rows
>DocsResultRow
doc
)post_changes
(viaChangesResult
results
>ChangesResultItem
doc
)post_find
(viaFindResult
docs
)post_partition_find
(viaFindResult
docs
)post_search
(viaSearchResult
rows
>SearchResultRow
doc
orSearchResult
groups
>SearchResultProperties
rows
>SearchResultRow
doc
)post_partition_search
(viaSearchResult
rows
>SearchResultRow
doc
orSearchResult
groups
>SearchResultProperties
rows
>SearchResultRow
doc
)post_view
(viaViewResult
rows
>ViewResultRow
doc
)post_partition_view
(viaViewResult
rows
>ViewResultRow
doc
)
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:1000042
Before:
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:1000042
After:
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