MagicStack / MagicStack/asyncpg

TempCluster() and pytest

Open
#789 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

* **asyncpg version**: 0.23.0
* **PostgreSQL version**: N/A
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: N/A
* **Python version**: 3.8.9 (but N/A)
* **Platform**: N/A
* **Do you use pgbouncer?**: N/A
* **Did you install asyncpg with pip?**: yes
* **If you built asyncpg locally, which version of Cython did you use?**:
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**:

This is issue which happens when using TempCluster() for testing as mentioned in https://github.com/MagicStack/asyncpg/issues/589.

Basically invoking cluster.start() causes an error when trying to use in environment that sets up own event loop (like pytest). Because `.start()` calls `self._test_connection(timeout=wait)` which creates and uses own event loop (https://github.com/MagicStack/asyncpg/blob/d08a9b8b9c2c68d469aeb9c4112d83c56c24f11c/asyncpg/cluster.py#L467).

This can be worked around by using `nest_asyncio` package, but it would be great if we could pass the event loop to the `start()` method so no hacking around that would be needed.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The reported failure is in asyncpg/cluster.py around TempCluster.start() and its _test_connection(timeout=wait) call. Reproduce the start path under pytest or another environment with its own event loop, then determine how the requested loop argument should flow through that path. Done means cluster.start() can use the caller's event loop without requiring nest_asyncio, with coverage for the reported scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.