Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enable ensure_ascii in custom jsonb encoder #880

Unanswered
FyZzyss asked this question in Q&A
Discussion options

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',
 )
You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

Can you elaborate on how exactly it "does not work" please?

You must be logged in to vote
1 reply
Comment options

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"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /