-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add transaction model aiopg #219
Conversation
Just for your information, you can put python3.5 tests into |
Codecov Report
@@ Coverage Diff @@
## master #219 +/- ##
=========================================
+ Coverage 93.23% 93.53% +0.3%
=========================================
Files 23 25 +2
Lines 3427 3648 +221
Branches 189 194 +5
=========================================
+ Hits 3195 3412 +217
- Misses 194 198 +4
Partials 38 38
Continue to review full report at Codecov.
|
@vir-mir would you add missing tests? |
@asvetlov hi! Yes. |
LGTM? |
please wait a bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transaction
class is perfect but I think we should add method factories to cursor for easy usage like
async with cur.begin():
...
async with cur.begin_nested():
...
For these methods we should choose appropriate default isolation level -- I have strong opinion that most of library users don't know about isolation levels at all.
At least it was very hard question on interviews provided by me.
aiopg/transaction.py
Outdated
__slots__ = ('_cur', '_is_begin', '_isolation', '_unique_id') | ||
|
||
def __init__(self, cur, isolation_level: IsolationLevel, | ||
readonly: bool = False, deferrable: bool = False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop spaces around =
.
Looks like bool=False
is the preferable notation for function annotations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good
@vir-mir we should decide: support typing annotations for the whole project or not. If we will decide to support -- we should add annotations to every public |
Exactly my thoughts, should we support external file like |
I believe we will add annotation eventually anyway, but lets drop it from this PR and add them separately with |
Hi. |
|
@asvetlov I'm add factories in cursor and drop spaces around example async def begin(engine):
async with engine.cursor() as cur:
async with cur.begin():
await cur.execute("insert into tbl values(1, 'data')")
async with cur.begin():
await cur.execute('select * from tbl')
row = await cur.fetchall()
assert row == [(22, 'read only'), (1, 'data'), ]
async def begin_nested(engine):
async with engine.cursor() as cur:
async with cur.begin_nested():
await cur.execute("insert into tbl values(1, 'data')")
try:
async with cur.begin_nested():
await cur.execute("insert into tbl values(1/0, 'no data')")
except psycopg2.DataError:
pass
async with cur.begin_nested():
await cur.execute("insert into tbl values(2, 'data')")
async with cur.begin_nested():
await cur.execute('select * from tbl')
row = await cur.fetchall()
assert row == [(22, 'read only'), (1, 'data'), (2, 'data'), ] |
resolve conflicts @asvetlov any news? |
Hello, everyone! |
9d17d08
to
d825cb6
Compare
@@ -146,6 +147,16 @@ def callproc(self, procname, parameters=None, *, timeout=None): | |||
else: | |||
yield from self._conn._poll(waiter, timeout) | |||
|
|||
def begin(self): | |||
return _TransactionBeginContextManager(self._transaction.begin()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not covered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return _TransactionBeginContextManager(self._transaction.begin()) | ||
|
||
def begin_nested(self): | ||
if not self._transaction.is_begin: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not called by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
@asyncio.coroutine | ||
def __aexit__(self, exc_type, exc_val, exc_tb): | ||
if exc_type is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d825cb6
to
c43c10f
Compare
Cool! |
Lets do docs in separate PR, this one already large.
…On Mon, Dec 4, 2017, 14:42 Andrew Svetlov ***@***.***> wrote:
Cool!
The code looks perfect but lacks documentation.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#219 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AANoZwJMw51cxPYUbIVlK_y-2B3hHInrks5s8-iugaJpZM4K8xsx>
.
|
Ok. @vir-mir please merge. Documentation is a show stopper for next release. |
Todo task
__slots__
aiopg/transaction.py:21