MagicStack / MagicStack/asyncpg
Application Flow Stuck Unless Connection is Explicitly Closed
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 8.1k
- Forks
- 468
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
* **asyncpg version**: 0.30.0
* **PostgreSQL version**: 16
* **Do you use a PostgreSQL SaaS? If so, which?**: Yes, I am using NeonDB
* **Can you reproduce the issue with a local PostgreSQL install?**: Didn't attempt it.
* **Python version**: 3.11.0
* **Platform**: Windows
* **Do you use pgbouncer?**: No
* **Did you install asyncpg with pip?**: Yes
* **If you built asyncpg locally, which version of Cython did you use?**: [Your Cython version if applicable]
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**: [Yes/No] I did not try uvloop
I'm encountering an issue where the flow of my application gets stuck unless the database connection is explicitly closed after a query, even though it should be managed automatically by the context manager.
**Code Example**:
```python
async def read_record(self, request_details: dict):
"""
Retrieve records based on conditions and request_type.
Args:
request_details (dict): The conditions including request_type.
Returns:
list: The records that match the conditions.
"""
table = self.get_table_name(request_details['request_type'])
conditions = {key: request_details[key] for key in request_details if key != 'request_type'}
condition_str = " AND ".join(f"{key} = ${i+1}" for i, key in enumerate(conditions.keys()))
query = f"SELECT * FROM {table} WHERE {condition_str};"
async with self.get_connection() as conn:
conn.add_log_listener(lambda connection, message: logger.info("PostgreSQL log message: %s", message))
result = await conn.fetch(query, *conditions.values())
logger.info("Fetched records: %s", result)
# await conn.close() # get's stuck without this line
return result
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem bereitgestellten asyncpg 0.30.0-Beispiel und reproduziere es unter Python 3.11, PostgreSQL 16 und Windows. Bestätige zunächst, ob das Problem bei einer lokalen PostgreSQL-Installation auftritt. Untersuche das Verhalten des asynchronen Kontextmanagers um `self.get_connection()` und vergleiche es mit dem Fall mit dem expliziten `conn.close()`; abgeschlossen ist die Aufgabe, wenn der Ablauf ohne diesen expliziten Aufruf zum Schließen abgeschlossen wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- postgresql, python
- Bereich
- backend, databases
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100