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

t.commit generates an error in version 0.5.3 #178

Open
dougmitarotonda opened this issue May 9, 2019 · 3 comments
Open

t.commit generates an error in version 0.5.3 #178

dougmitarotonda opened this issue May 9, 2019 · 3 comments

Comments

@dougmitarotonda
Copy link

In the Features section of the documentation for version 0.5.3, it says

"Transactions: t = Database.transaction(); t.commit()."

However, I get an error when trying to do this:

>>> url = '...'
>>> db = records.Database(url)
>>> t = db.transaction()
>>> t.commit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: '_GeneratorContextManager' object has no attribute 'commit'

However, if I install version 0.5.2, the above code works.

How is the usage of this feature intended to work in version 0.5.3?

@TokenChingy
Copy link

Can confirm, this is happening to me as well.

My code:

db = records.Database(...uri)
tx = db.transaction()
try:
    db.query(...query)
    db.query(...another_query)
    tx.commit()
except:
    tx.rollback()
...
AttributeError: '_GeneratorContextManager' object has no attribute 'commit'
...
AttributeError: '_GeneratorContextManager' object has no attribute 'rollback'

@TokenChingy
Copy link

TokenChingy commented May 15, 2019

Nevermind! I figured it out, my code is wrong.

After looking at records.py and the unit tests, this is the proper way for using transactions:

db = records.Database(...uri)
conn = db.get_connection()
tx = conn.transaction()

try:
    db.query(...query)
    db.query(...another_query)
    tx.commit()
except:
    tx.rollback()
finally:
    conn.close()

EDIT: Could we improve the documentation for records?

@dougmitarotonda
Copy link
Author

Many thanks for looking into this, I'll keep the ticket open as a request to then update the documentation to read:

"Transactions: conn = db.get_connection(); t = conn.transaction(); t.commit()."

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