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

Using context manager fails if used more than once #54

Closed
ecederstrand opened this issue Jul 29, 2016 · 3 comments
Closed

Using context manager fails if used more than once #54

ecederstrand opened this issue Jul 29, 2016 · 3 comments
Labels

Comments

@ecederstrand
Copy link
Contributor

ecederstrand commented Jul 29, 2016

>>> foo = SqliteDict('foo.sqlite')
>>> with foo:
...    foo[1] = 2
... 
>>> with foo:
...    foo[1] = 2
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/lib/python3.4/site-packages/sqlitedict.py", line 233, in __setitem__
    self.conn.execute(ADD_ITEM, (key, encode(value)))
AttributeError: 'NoneType' object has no attribute 'execute'

This is because __exit__ calls close() which deletes self.conn.

it seems __enter__ should check that self.conn exists and create it otherwise. I could just go through __init__ once more, but __init__ contains unnecessary actions like CREATE TABLE ...

I can create a patch if this issue is accepted.

@piskvorky
Copy link
Owner

Hmm, looks like a bug, thanks.

A PR would be welcome!

@ecederstrand
Copy link
Contributor Author

Fixed in PR #55

@tmylk tmylk closed this as completed in aad0741 Aug 26, 2016
tmylk added a commit that referenced this issue Aug 26, 2016
Let __enter__ re-open a closed connection. Fixes #54
@piskvorky
Copy link
Owner

Thanks @ecederstrand !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants