jur9526 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

Mapping `get` method forces to pass default value #148

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. define document
>>> class Doc(Document):
>>>   pass
2. store it
>>> doc = Doc(id='abc')
>>> doc.store(db)
3. Try next code
>>> doc = db['abc']
>>> doc.get('are you real?')
None
>>> doc = Doc.load('abc', db)
>>> doc.get('are you real?')

What is the expected output? What do you see instead?
I expected to have same behavior as for raw documents - get method returns None 
if item was not found, but I see this exception instead:
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
TypeError: get() takes exactly 3 arguments (2 given)

What version of the product are you using? On what operating system?
couchdb-python-0.9@40a0a8cdf420

Please provide any additional information below.
I suppose that raw documents and "objective" documents must have same behavior 
for same methods, especially due to dynamic nature of couchdb. why not?

Original issue reported on code.google.com by kxepal on 10 Sep 2010 at 9:44

GoogleCodeExporter commented 9 years ago
Thanks for the bug report. I agree that the get() method should have a 
default=None arg to match the dict API.

However, in case you haven't noticed yet, mapping.Document does not support 
dynamic items - only explicitly added fields are stored. Defined fields will 
have a default value of None so the get() method is probably redundant in most 
situations.

Original comment by matt.goo...@gmail.com on 10 Sep 2010 at 1:06

GoogleCodeExporter commented 9 years ago
Dynamic fields may be occured by document model inheritance and also you may 
add/remove fields in any time for your model.

Original comment by kxepal on 10 Sep 2010 at 1:15

GoogleCodeExporter commented 9 years ago
Fixed in r22409c4bea.

Original comment by matt.goo...@gmail.com on 10 Sep 2010 at 1:19