MagicStack / MagicStack/asyncpg

Segfault with NULL value in cell

Open
#764 1 comment 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: 13
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : No
  • Python version: 3.8
  • Platform: Ubuntu Xenial
  • Did you install asyncpg with pip?: Yes
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : Yes

My table looks like this, and is using the citext extension

CREATE TABLE public.items
(
    item_id     bigint                       NOT NULL,
    tags        citext[] default '{}' not null
);

I have a simple query

query = """SELECT tags FROM items WHERE item_id = 304028"""

async with pool.acquire() as c:
    result = await c.fetchval(query)
    print(result)
    val = result[2]

This gives the following output
['debuff', 'buff', <NULL>]
And upon trying to access the second item of the list results a segmentation fault occurs.

Inspecting the database with PyCharm's database tab shows this cell as having the value {debuff,buff,""}

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

No source files or tests are named. Start by reproducing the reported asyncpg 0.23.0 query against the provided PostgreSQL schema and inspect how the citext[] result containing a NULL element is decoded; done means the same access no longer segfaults and the NULL value is handled safely.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.