Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError is raised when using find #2

Open
alfredodeza opened this issue Oct 30, 2014 · 2 comments
Open

TypeError is raised when using find #2

alfredodeza opened this issue Oct 30, 2014 · 2 comments

Comments

@alfredodeza
Copy link
Contributor

I am not even sure how to replicate this, but tracing, _load is getting a list as the second argument that
contains the actual match:

id is: 2
data is: [{"username": "alfredo", "secret": "secret", "_id": 1}]

Traceback (most recent call last):
  File "/Users/alfredo/.virtualenvs/wari/bin/wari", line 10, in <module>
    execfile(__file__)
  File "/Users/alfredo/python/wari/bin/wari", line 6, in <module>
    main.Wari()
  File "/Users/alfredo/python/wari/wari/main.py", line 35, in __init__
    self.main(argv)
  File "/Users/alfredo/python/wari/wari/decorators.py", line 45, in newfunc
    return f(*a, **kw)
  File "/Users/alfredo/python/wari/wari/main.py", line 57, in main
    parser.dispatch()
  File "/Users/alfredo/.virtualenvs/wari/lib/python2.7/site-packages/tambo-0.0.8-py2.7.egg/tambo/dispatcher.py", line 18, in dispatch
    return instance.parse_args()
  File "/Users/alfredo/python/wari/wari/hotp.py", line 83, in parse_args
    return self.remove(parser.get('remove'))
  File "/Users/alfredo/python/wari/wari/hotp.py", line 106, in remove
    documents = db.collection.find({'username': username}, limit=1)
  File "/Users/alfredo/python/otp/nosqlite/nosqlite.py", line 185, in find
    for match in ifilter(apply, starmap(self._load, cursor.fetchall())):
  File "/Users/alfredo/python/otp/nosqlite/nosqlite.py", line 170, in _load
    document['_id'] = id
TypeError: list indices must be integers, not str
@alfredodeza alfredodeza changed the title if the collection is empty a TypeError is raised when using find TypeError is raised when using find Oct 30, 2014
@alfredodeza
Copy link
Contributor Author

Output of the database:

INSERT INTO wari VALUES(2,'[{"username": "alfredo", "secret": "secret", "_id": 1}]');
INSERT INTO wari VALUES(3,'[{"username": "alfredo", "secret": "secret", "_id": 1}]');

It looks like at some point I inserted a list instead of a dict.

@shaunduncan
Copy link
Owner

I'll probably want to add in some level of checking about the argument given to .insert(). My thoughts right now is that .insert() would have the following behavior

foo.insert({'foo': 'bar'})  # inserts a single document
foo.insert([{'foo': 'bar'}, {'baz': 'qux'}])  # inserts two documents
foo.insert({'foo': 'bar'}, {'baz': 'qux'})  # inserts two documents

Thoughts?

plutec pushed a commit to plutec/nosqlite that referenced this issue Aug 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants