This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/main by this push:
     new 7474c4b64 PROTON-2926: Message ttl=0 improvements
7474c4b64 is described below

commit 7474c4b64ac7bce2ffbf24b3650d74dda0f4f6c7
Author: Andrew Stitcher <[email protected]>
AuthorDate: Thu Mar 19 17:51:12 2026 -0400

    PROTON-2926: Message ttl=0 improvements
    
    - Document that ttl=0 represents no ttl for the proton-c API.
    - Change python API to accept None and treat it as no expiry
    - Change python API to return float inf for no expiry
      This is the closest correct semantic value that can be represented in a
      python float.
    
    Closes #348
---
 c/include/proton/message.h           |  4 ++++
 python/proton/_message.py            | 12 ++++++++----
 python/tests/proton_tests/message.py |  5 +++--
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/c/include/proton/message.h b/c/include/proton/message.h
index 6a31eafaa..c6dea9285 100644
--- a/c/include/proton/message.h
+++ b/c/include/proton/message.h
@@ -193,6 +193,10 @@ PN_EXTERN int            pn_message_set_priority          
(pn_message_t *msg, ui
  * dead. Once a message is considered dead it may be dropped. Use
  * ::pn_message_set_ttl() to set the ttl for a message.
  *
+ * In this API a value of zero for the ttl means that the message has
+ * no ttl and never expires. If the ttl is never set on a message this
+ * will be the default value for the ttl.
+ *
  * @param[in] msg a message object
  * @return the ttl in milliseconds
  */
diff --git a/python/proton/_message.py b/python/proton/_message.py
index 56e985c02..3464c5c93 100644
--- a/python/proton/_message.py
+++ b/python/proton/_message.py
@@ -37,6 +37,7 @@ from ._common import millis2secs, secs2millis
 from ._data import char, Data, symbol, ulong, AnnotationDict
 from ._endpoints import Link
 from ._exceptions import EXCEPTIONS, MessageException
+from math import inf
 from uuid import UUID
 from typing import Optional, Union, TYPE_CHECKING, overload
 
@@ -224,15 +225,18 @@ class Message:
     @property
     def ttl(self) -> float:
         """The time to live of the message measured in seconds. Expired 
messages
-        may be dropped.
+        may be dropped. A value of ``inf`` indicates that the message has no 
ttl and never expires.
 
         :raise: :exc:`MessageException` if there is any Proton error when 
using the setter.
         """
-        return millis2secs(pn_message_get_ttl(self._msg))
+        ttl = pn_message_get_ttl(self._msg)
+        if ttl == 0:
+            return inf
+        return millis2secs(ttl)
 
     @ttl.setter
-    def ttl(self, value: Union[float, int]) -> None:
-        self._check(pn_message_set_ttl(self._msg, secs2millis(value)))
+    def ttl(self, value: Union[float, int, None]) -> None:
+        self._check(pn_message_set_ttl(self._msg, secs2millis(0 if value is 
None or value == inf else value)))
 
     @property
     def first_acquirer(self) -> bool:
diff --git a/python/tests/proton_tests/message.py 
b/python/tests/proton_tests/message.py
index f0b5bb1de..8ab1a5441 100644
--- a/python/tests/proton_tests/message.py
+++ b/python/tests/proton_tests/message.py
@@ -17,8 +17,9 @@
 # under the License.
 #
 
-from uuid import uuid4
+from math import inf
 from sys import version_info
+from uuid import uuid4
 
 from proton import Data, Message, MessageException, byte, char, decimal32, 
decimal64, decimal128, float32, int32, \
     short, symbol, timestamp, ubyte, uint, ulong, ushort
@@ -67,7 +68,7 @@ class AccessorsTest(Test):
         self._test("priority", Message.DEFAULT_PRIORITY, range(0, 255))
 
     def testTtl(self):
-        self._test("ttl", 0, range(12345, 54321))
+        self._test("ttl", inf, range(12345, 54321))
 
     def testFirstAcquirer(self):
         self._test("first_acquirer", False, (True, False))


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to