This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: dbshelve.py throws exception: AttributeError: 'DB' object has no attribute '__iter__'
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: adam-collard, jcea, r.david.murray, rhettinger
Priority: normal Keywords: easy, patch

Created on 2010-02-21 15:44 by adam-collard, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
dbshelve_example.py adam-collard, 2010-02-21 17:14 Simple example that generates traceback
dbshelve_dictmixin.patch r.david.murray, 2010-02-21 22:15
Messages (8)
msg99667 - (view) Author: Adam Collard (adam-collard) * Date: 2010-02-21 15:44
Originally reported at:
  https://bugs.edge.launchpad.net/bugs/384602

In Python 2.6, the dbshelve.py module throws an AttributeError exception whenever a call is made to a method that depends upon an __iter__ method.  The exception is:

  File "/usr/lib/python2.6/bsddb/dbshelve.py", line 167, in __iter__
    return self.db.__iter__()
AttributeError: 'DB' object has no attribute '__iter__'

This means that, if mydb is an istance of a DB object, the following examples will fail:

    for key in mydb: print key
 
    print (k for k in mydb.iterkeys())

    for k, d in mydb.itervalues(): print k, d

and many other statements depending on iterable(mydb) being true

Note that, in Python 2.5, these examples work and no exception is thrown.  In fact, if you have both 2.5 and 2.6 installed on the same system, you can run the same program containing code as above with Python2.5 without issue while running it under Python 2.6 raises the exception seen above.
msg99669 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-21 16:49
Could you please provide a complete example that demonstrates the problem?  A naive example using shelve with a dbhash database seems to work fine.
msg99672 - (view) Author: Adam Collard (adam-collard) * Date: 2010-02-21 17:14
Attached a simple example.
msg99678 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-21 20:09
The bug seems to have been introduced by an incomplete or incorrect translation to the newer idiom (DictMixin to MutableMapping).  Since bsddb is gone in py3, I'm inclined to fix it by just going back to using DictMixin.  There are no tests for the DictMixin functionality added in Python 2.3.
msg99692 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-21 22:15
Here's a patch.  test_bsddb3 still passes with this patch applied on trunk.
msg99832 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-02-22 21:07
+1
msg99997 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-24 02:38
Committed to trunk in r78412 and 2.6 in r78413.
msg101276 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2010-03-18 19:50
This bug was introduced in pybsddb 4.7.2, when migration to ABC (Abstract Base Classes).

I have solved it in 4.8.3+, and added relevant testcases.

I plan to integrate 4.8.3+ in Python 2.7. See issue8156.
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52223
2010-03-18 19:50:02jceasetmessages: + msg101276
2010-02-24 02:38:29r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg99997

stage: patch review -> resolved
2010-02-22 21:07:44rhettingersetnosy: + rhettinger
messages: + msg99832
2010-02-21 22:15:19r.david.murraysetfiles: + dbshelve_dictmixin.patch
messages: + msg99692

assignee: r.david.murray
keywords: + patch
stage: test needed -> patch review
2010-02-21 20:09:32r.david.murraysetnosy: + jcea
messages: + msg99678

components: + Library (Lib)
keywords: + easy
2010-02-21 17:14:11adam-collardsetfiles: + dbshelve_example.py

messages: + msg99672
2010-02-21 16:49:18r.david.murraysetpriority: normal

type: behavior
versions: + Python 2.6, Python 2.7
nosy: + r.david.murray

messages: + msg99669
stage: test needed
2010-02-21 15:44:15adam-collardcreate