Skip to content

Commit 01dbe32

Browse files
Copilotjason810496
andcommitted
Fix vt=0 being ignored in read() method (#11)
* feat: add set_vt_method and usage docs * test: add test for set_vt method * Initial plan * Fix bug: vt=0 should be valid visibility timeout value Added check for `vt is None` in the read() method to properly handle vt=0. Previously, vt=0 would be treated as falsy and would default to self.vt (30 seconds). Now vt=0 correctly sets the visibility timeout to 0 seconds as expected. Also added test case to verify vt=0 works correctly. Co-authored-by: jason810496 <[email protected]> --------- Co-authored-by: jason810496 <[email protected]> Co-authored-by: LIU ZHE YOU <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent 91c4bd0 commit 01dbe32

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

pgmq_sqlalchemy/queue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ def read(self, queue_name: str, vt: Optional[int] = None) -> Optional[Message]:
573573
574574
575575
"""
576+
if vt is None:
577+
vt = self.vt
576578
if self.is_async:
577579
return self.loop.run_until_complete(self._read_async(queue_name, vt))
578580
return self._read_sync(queue_name, vt)

tests/test_queue.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ def test_send_and_read_msg_with_vt_and_delay(pgmq_setup_teardown: PGMQ_WITH_QUEU
162162
assert msg_read.msg_id == msg_id
163163

164164

165+
def test_send_and_read_msg_with_vt_zero(pgmq_setup_teardown: PGMQ_WITH_QUEUE):
166+
"""Test that vt=0 works correctly and message becomes visible immediately."""
167+
pgmq, queue_name = pgmq_setup_teardown
168+
msg = MSG
169+
msg_id: int = pgmq.send(queue_name, msg)
170+
# Read with vt=0 means message should be immediately visible again
171+
msg_read = pgmq.read(queue_name, vt=0)
172+
assert msg_read.message == msg
173+
assert msg_read.msg_id == msg_id
174+
# Message should be visible immediately (no waiting)
175+
msg_read = pgmq.read(queue_name)
176+
assert msg_read.message == msg
177+
assert msg_read.msg_id == msg_id
178+
179+
165180
def test_read_empty_queue(pgmq_setup_teardown: PGMQ_WITH_QUEUE):
166181
pgmq, queue_name = pgmq_setup_teardown
167182
msg_read = pgmq.read(queue_name)

0 commit comments

Comments
 (0)