Skip to content

add support for "async with cursor_context()"#265

Open
thehesiod wants to merge 41 commits into
aio-libs:masterfrom
thehesiod-forks:async_cursor
Open

add support for "async with cursor_context()"#265
thehesiod wants to merge 41 commits into
aio-libs:masterfrom
thehesiod-forks:async_cursor

Conversation

@thehesiod

@thehesiod thehesiod commented Jan 26, 2017

Copy link
Copy Markdown
Contributor

resolves #264

@codecov-io

codecov-io commented Jan 26, 2017

Copy link
Copy Markdown

Codecov Report

Merging #265 into master will increase coverage by 0.28%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #265      +/-   ##
==========================================
+ Coverage   93.66%   93.95%   +0.28%     
==========================================
  Files          25       25              
  Lines        3744     3787      +43     
  Branches      199      202       +3     
==========================================
+ Hits         3507     3558      +51     
+ Misses        199      191       -8     
  Partials       38       38
Impacted Files Coverage Δ
aiopg/utils.py 90.05% <100%> (+6.61%) ⬆️
aiopg/pool.py 98.91% <100%> (-0.02%) ⬇️
tests/test_connection.py 98.23% <100%> (ø) ⬆️
aiopg/cursor.py 98.82% <100%> (+0.03%) ⬆️
tests/pep492/test_async_await.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8cea23e...1133c6a. Read the comment docs.

@jettify

jettify commented Jan 29, 2017

Copy link
Copy Markdown
Member

Good point, is it possible to hack something so we can support both: async with (await pool.cursor()) and async with pool.cursor() and then deprecate first example in next release?

@thehesiod

Copy link
Copy Markdown
Contributor Author

ya I'll work something up in the next few days

@thehesiod

Copy link
Copy Markdown
Contributor Author

@jettify ok, I think I've done it to have the current method backwards and forwards compatible. Getting it to work was tricky. Just tweaking the unittests now for code coverage. Let me know what you think.

@thehesiod

Copy link
Copy Markdown
Contributor Author

@jettify ping :)

@k4nar

k4nar commented Jul 4, 2017

Copy link
Copy Markdown

I'm using this branch in development and it works very well 👍 .

Comment thread aiopg/utils.py Outdated

def __iter__(self):
# This will get hit if you use "yield from pool.cursor()"
if PY_35:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need this warning.
yield from pool.cursor() works pretty fine even on Python 3.6.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just so they to start using async with pool.cursor() instead of with (yield from pool.cursor()) so that the cursor will be actually closed at the end of the context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in the future because right now it doesn't actually wait for the connection to be closed.

Comment thread aiopg/utils.py
self._pool = pool
self._conn = conn

@property

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this property?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thehesiod added 2 commits July 4, 2017 10:50
- simplifies changes to _PoolCursorContextManager
- bumps up docker client to work with latest docker for mac
- bumps psycopg2 to latest release for testing
- fixes issue with dsn comparison
@thehesiod

Copy link
Copy Markdown
Contributor Author

@jettify I removed the deprecation warning per @asvetlov since it does technically work, we can deprecate it later I suppose.

@thehesiod

Copy link
Copy Markdown
Contributor Author

hmm, @asvetlov let me know what you think of this error: https://travis-ci.org/aio-libs/aiopg/jobs/250130251#L1360

@thehesiod

Copy link
Copy Markdown
Contributor Author

hmm, this was supposed to have been fixed by 8ca948e

@thehesiod

Copy link
Copy Markdown
Contributor Author

ok, looks like you later refactored it in 2a72b60#diff-3416729d6745fac0ca3dd44b22a69068 however it looks like it doesn't work with the latest psycopg2, so I'll let you decide how you want to fix it


async def test_pool_cursor_await_context_manager(loop, pg_params):
async with aiopg.create_pool(loop=loop, **pg_params) as pool:
with (await pool.cursor()) as cursor:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the yield from form be tested also?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is tested in test_close_running_cursor

@thehesiod

Copy link
Copy Markdown
Contributor Author

@asvetlov ok everything is now passing, let me know if you'd like any other changes

@thehesiod

thehesiod commented Mar 17, 2018

Copy link
Copy Markdown
Contributor Author

@asvetlov anything left? let's get this merged :)

(after I fix this having broken after merging from master)

@thehesiod

Copy link
Copy Markdown
Contributor Author

@vir-mir @asvetlov can we get this merged?

@asvetlov

Copy link
Copy Markdown
Member

I can take a look in a few days

@thehesiod

Copy link
Copy Markdown
Contributor Author

FYI failures not my fault

# Conflicts:
#	aiopg/cursor.py
#	tests/pep492/test_async_await.py
@thehesiod

Copy link
Copy Markdown
Contributor Author

@asvetlov @vir-mir ? :)

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Successfully merging this pull request may close these issues.

cleanup aiopg.pool.Pool.cursor method

7 participants