Skip to content

Commit

Permalink
pgmq-python: explicitly cast types in send_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckHend committed Dec 19, 2024
1 parent 8e6df4b commit 854000b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tembo-pgmq-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tembo-pgmq-python"
version = "0.9.1"
version = "0.9.2"
description = "Python client for the PGMQ Postgres extension."
authors = ["Adam Hendel <[email protected]>"]
license = "PostgreSQL"
Expand Down
4 changes: 2 additions & 2 deletions tembo-pgmq-python/tembo_pgmq_python/async_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ async def send_batch(self, queue: str, messages: List[dict], delay: int = 0, con
else:
return await self._send_batch_internal(queue, messages, delay, conn)

async def _send_batch_internal(self, queue, messages, delay, conn):
async def _send_batch_internal(self, queue: str, messages: List[dict], delay: int, conn):
self.logger.debug(f"Sending batch of messages to queue '{queue}' with delay={delay}")
jsonb_array = [dumps(message).decode("utf-8") for message in messages]
result = await conn.fetch(
"SELECT * FROM pgmq.send_batch($1, $2::jsonb[], $3);",
"SELECT * FROM pgmq.send_batch($1::string, $2::jsonb[], $3::integer);",
queue,
jsonb_array,
delay,
Expand Down
2 changes: 1 addition & 1 deletion tembo-pgmq-python/tembo_pgmq_python/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def send(self, queue: str, message: dict, delay: int = 0, conn=None) -> int:
def send_batch(self, queue: str, messages: List[dict], delay: int = 0, conn=None) -> List[int]:
"""Send a batch of messages to a queue."""
self.logger.debug(f"send_batch called with conn: {conn}")
query = "select * from pgmq.send_batch(%s, %s, %s);"
query = "select * from pgmq.send_batch(%s::text, %s::jsonb[], %s::integer);"
params = [queue, [Jsonb(message) for message in messages], delay]
result = self._execute_query_with_result(query, params, conn=conn)
return [message[0] for message in result]
Expand Down

0 comments on commit 854000b

Please sign in to comment.