Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asyncpg.exceptions.DataError: invalid input for query argument python

I have a problem insert to PostgreSQL. The column I'm trying to insert is of type JSONB. The type of the object is Counter().

In production it is working, but locally it raises the following error:

asyncpg.exceptions.DataError: invalid input for query argument $16: Counter({'clearmeleva': 1, 'cr7fragrance... (expected str, got Counter)

Thank you!

like image 815
תומר פישר Avatar asked Aug 28 '26 07:08

תומר פישר


1 Answers

As stated in asyncpg documentation, the corresponding Python type for JSON and JSONB is a string.
So if the column where you want to add your data is of type JSONB, try to convert your Counter-type object to a string

new_counter_type_obj = str(counter_type_obj)

and then pass it to asyncpg.

like image 126
Tms91 Avatar answered Aug 30 '26 19:08

Tms91



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!