On 16 November 2011 06:24, Thomas <thomm
...@gmx.net> wrote:
> I am wondering if and why it's standard behavior that couchdb-python
> is adding empty attributes of an object to couchdb. I am just feeling
> when an attribute (e.g. name) is None, then it would not end up in the
> DB. As i understood CouchDB is returning null for non-existing and
> empty attributes anyway.
couchdb-python's couchdb.client module doesn't alter attributes (apart
from _id and _rev) at all, it sends whatever the application gives it
to the CouchDB server. For some applications, the absence of an
attribute vs a None value may even be significant. The couchdb.mapping
Document seems to set all its schema attributes to None during
__init__ but that doesn't seem totally unreasonable given that
attribute access has to return *something*.
Like couchdb.client, CouchDB also stores whatever it's given. It's
really just the default JavaScript view engine that treats
JavaScript's undefined as a null. If you need to, you can
differentiate between undefined and null in a map function by using
JS's === strict comparison operator.
> This way attributes could maybe assigned to a doc dynamically. (Some
> docs have it, some not, ...)
Yep, and this is the the behaviour you get with couchb.client already.
There may be an argument for making couchdb.mapping produce sparse
documents but not set and None are still different and I'm not
convinced it would be practical to use if document attributes
disappeared to represent the not set case.
> Maybe I am thinking into the absolute wrong direction.
> Thomas