-
Notifications
You must be signed in to change notification settings - Fork 431
-
Hello.
I'm trying to write to a json field with ascii characters. This does not work even with ensure_ascii=False
The encoding in the database is utf-8, so it's not about it. How to fix it?
My code:
@staticmethod
def _encode_jsonb(value: Union[Dict, List]) -> str:
return json.dumps(value, default=str, ensure_ascii=False)
@staticmethod
def _decode_jsonb(value: str) -> Union[Dict, List]:
return json.loads(value)
async def _init_connection(self, conn: asyncpg.Connection) -> None:
await conn.set_type_codec(
'jsonb',
encoder=self._encode_jsonb,
decoder=self._decode_jsonb,
schema='pg_catalog',
)
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
Can you elaborate on how exactly it "does not work" please?
Beta Was this translation helpful? Give feedback.
All reactions
-
The data is displayed correctly in all logs. After writing to the database, incorrect text in jsonb field is obtained:
{"error_id": null, "code": 1, "text": "\u0422\u0430\u0439\u043c\u0430\u0443\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438", "type": "timeout"}
Beta Was this translation helpful? Give feedback.