MagicStack / MagicStack/asyncpg

no binary format encoder for type jsonb

オープン
#1,144 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
8.1k
フォーク
468
PR マージ指標
30日以内にマージされた PR はありません

説明

  • asyncpg version: 0.29.0

  • PostgreSQL version: 16

  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    :

  • Python version: 3.11

  • Platform: 5.10.0-21-arm64 #1 SMP Debian 5.10.162-1 (2023-01-21) aarch64 GNU/Linux

  • Do you use pgbouncer?:no

  • 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?
    : yes

,asyncpg.exceptions._base.InternalClientError: no binary format encoder for type jsonb (OID 3802)

async def insert_binary(self, table, rows):
	if rows:
		rows = common_function.convert_data_type(rows, decimal.Decimal, float, )
		columms = rows[0].keys()
		data = []
		for row_index, rows_once in enumerate(rows):
			data_once = [rows_once[columns_once] for columns_once in columms]
			data.append(tuple(data_once))
		conn = await self.connect()
		await conn.copy_records_to_table(table,records=data, columns=rows[0].keys())
		await conn.fetch('SELECT 1')
		await conn.close()

I've tried various methods, but I couldn't manage to insert binary data. I've tried using decoders and other approaches. It seems like it needs a binary decoder, not a text one, but I haven't figured out how to represent it in binary. I'd appreciate any help.


await conn.set_type_codec(
	"jsonb",
	encoder=lambda data: b"\x01" + common_function.decoder.dumps(data, False),
	decoder=lambda data: common_function.decoder.loads(data[1:]),
	schema="pg_catalog",
	format="binary"
)
await conn.set_type_codec(
	'numeric'
	, encoder = lambda f: str(f).encode('utf8')
	, decoder = lambda b: b.decode('utf8')
	, schema='pg_catalog'
	, format='binary'
)


"This also doesn't work."

"I replaced 'numeric' with 'float' (database field types), and the problem 'no binary format encoder for type numeric' disappeared. However, I couldn't figure out which format decoder is needed for JSON."

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

copy_records_to_table と set_type_codec から始め、binary format を使用した PostgreSQL jsonb(OID 3802)で報告された失敗を再現します。既存の JSON および数値 codec の処理を追跡し、その後、binary format の jsonb レコードが報告された encoder エラーなしで受け入れられることを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
postgresql, python
領域
databases
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。