MagicStack / MagicStack/asyncpg

"AttributeError: 'NoneType' object has no attribute 'decode'" when executing empty script

Offen
#1,259 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
468
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Wouldn't it be natural that executing a script with only comments is a no-op returning OK?
Such that for example commenting out the contents of a migration script while developing runs the script as a no-op.

Instead what happens when running this:
```
import os
import asyncpg
import asyncio

async def main():
conn = await asyncpg.connect(os.environ["DATABASE_URI"])
async with conn.transaction():
await conn.execute("-- hello")

if __name__ == "__main__":
asyncio.run(main())
```

Is this:
```
Traceback (most recent call last):
File "/home/msa/dev/sandbox/pgtesting/hello.py", line 13, in
asyncio.run(main())
~~~~~~~~~~~^^^^^^^^
File "/home/msa/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 194, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "/home/msa/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/home/msa/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/home/msa/dev/sandbox/pgtesting/hello.py", line 9, in main
await conn.execute("-- hello")
File "/home/msa/dev/sandbox/pgtesting/.venv/lib/python3.13/site-packages/asyncpg/connection.py", line 349, in execute
result = await self._protocol.query(query, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "asyncpg/protocol/protocol.pyx", line 375, in query
File "asyncpg/protocol/protocol.pyx", line 888, in asyncpg.protocol.protocol.BaseProtocol._dispatch_result
File "asyncpg/protocol/protocol.pyx", line 815, in asyncpg.protocol.protocol.BaseProtocol._on_result__simple_query
AttributeError: 'NoneType' object has no attribute 'decode'
```
Setup is just
```
mkdir hello
cd hello
uv init .
uv add asyncpg
export DATABUTTON_URI="something"
uv run hello.py # above example
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit asyncpg/connection.py bei Connection.execute und verfolge den in asyncpg/protocol/protocol.pyx gezeigten Protokoll-Abfragepfad, insbesondere _on_result__simple_query. Reproduziere die Abfrage, die nur aus einem Kommentar besteht, und füge anschließend Tests hinzu oder aktualisiere die Testabdeckung so, dass sie erfolgreich abgeschlossen wird, ohne den NoneType-Dekodierungsfehler, und normale Ergebnisse für nichtleere Abfragen beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, python
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.