MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.89k stars 399 forks source link

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

Open tomerTcm opened 3 years ago

tomerTcm commented 3 years ago

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().

At production its working but locally I have a problem.

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

Why at prod is working and locally its throwing me this error ?

Thank you!

tomerTcm commented 3 years ago

Its working if I convert to dict and do json.dumps but it fail on something else:

Traceback (most recent call last):
  File "asyncpg/protocol/prepared_stmt.pyx", line 155, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
  File "asyncpg/protocol/codecs/base.pyx", line 193, in asyncpg.protocol.protocol.Codec.encode
  File "asyncpg/protocol/codecs/base.pyx", line 104, in asyncpg.protocol.protocol.Codec.encode_scalar
  File "asyncpg/protocol/codecs/array.pyx", line 853, in asyncpg.protocol.protocol.arraytext_encode
  File "asyncpg/protocol/codecs/array.pyx", line 115, in asyncpg.protocol.protocol.array_encode
TypeError: a sized iterable container expected (got type 'str')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tomerfi1210/ninja/ares/ares/orchestration/dispatchers/__init__.py", line 13, in dispatch
    await handle(conf, resource)
  File "/home/tomerfi1210/ninja/ares/ares/orchestration/dispatchers/instagram.py", line 99, in insert_profile_data
    r = await conf.pg.fetchrow(
  File "/home/tomerfi1210/ninja/ares/venv/lib/python3.8/site-packages/asyncpg/pool.py", line 579, in fetchrow
    return await con.fetchrow(query, *args, timeout=timeout)
  File "/home/tomerfi1210/ninja/ares/venv/lib/python3.8/site-packages/asyncpg/connection.py", line 641, in fetchrow
    data = await self._execute(
  File "/home/tomerfi1210/ninja/ares/venv/lib/python3.8/site-packages/asyncpg/connection.py", line 1625, in _execute
    result, _ = await self.__execute(
  File "/home/tomerfi1210/ninja/ares/venv/lib/python3.8/site-packages/asyncpg/connection.py", line 1650, in __execute
    return await self._do_execute(
  File "/home/tomerfi1210/ninja/ares/venv/lib/python3.8/site-packages/asyncpg/connection.py", line 1697, in _do_execute
    result = await executor(stmt, None)
  File "asyncpg/protocol/protocol.pyx", line 183, in bind_execute
  File "asyncpg/protocol/prepared_stmt.pyx", line 171, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
asyncpg.exceptions.DataError: invalid input for query argument $51: '[]' (a sized iterable container expected (got type 'str'))
2021-07-29 10:48:57,210 __init__:43 ERROR - got 'str' object has no attribute 'items' while trying to process: {'job_type': 'instagram:profile', 'payload': {'username': 'cristiano'}, 'job_id': 'b6b251ca-1447-43fc-90ce-ed3fe8085d9f'}
Traceback (most recent call last):
  File "/home/tomerfi1210/ninja/ares/ares/orchestration/__init__.py", line 39, in run_job
    async for resource in process_job(conf, payload):
  File "/home/tomerfi1210/ninja/ares/ares/orchestration/processors/__init__.py", line 25, in process_job
    async for resource in processor.generate_resources():
  File "/home/tomerfi1210/ninja/ares/ares/orchestration/processors/base.py", line 118, in generate_resources
    async for r in self.process():
  File "/home/tomerfi1210/ninja/ares/ares/orchestration/processors/base.py", line 110, in process
    async for result in analyzed:
  File "/home/tomerfi1210/ninja/ares/ares/orchestration/processors/instagram.py", line 200, in analyze
    for mention, count in profile['new_mentions'].items():
AttributeError: 'str' object has no attribute 'items'
Locvic commented 1 year ago

was this ever solved?