From a47b755d91b0f237353c7d92a8342d203a4db23f Mon Sep 17 00:00:00 2001 From: Johannes Martinsson Date: Tue, 19 May 2026 11:37:25 +0200 Subject: [PATCH] Do not coerce int properties if value already int If (the priority) property already is an integer, skip the int coercion and notably skip the warning about int coercion. Add a trival test checking that int priority properties goes through _coerce_properties unchanged. --- rabbitpy/message.py | 2 +- tests/test_message.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/rabbitpy/message.py b/rabbitpy/message.py index a0d699a..c76e6c5 100644 --- a/rabbitpy/message.py +++ b/rabbitpy/message.py @@ -370,7 +370,7 @@ def _coerce_properties(self) -> None: elif not isinstance(value, str): LOGGER.warning('Coercing property %s to str', key) self.properties[key] = str(value) - elif python_type == 'int': + elif python_type == 'int' and not isinstance(value, int): LOGGER.warning('Coercing property %s to int', key) try: self.properties[key] = int(value) diff --git a/tests/test_message.py b/tests/test_message.py index d531083..7fe8c3b 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -366,6 +366,12 @@ def test_coerce_property_str_to_int(self): self.msg._coerce_properties() self.assertIsInstance(self.msg.properties['priority'], int) + def test_coerce_property_int_stays_int(self): + self.msg.properties['priority'] = 9 + self.msg._coerce_properties() + self.assertIsInstance(self.msg.properties['priority'], int) + self.assertEqual(self.msg.properties['priority'], 9) + def test_coerce_property_str_to_empty_dict(self): self.msg.properties['headers'] = '9' self.msg._coerce_properties()