Repository navigation
Accept AMQP field arrays in Message.headers #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
pianoman19372
wants to merge
1
commit into
gmr:main
from
pianoman19372:fix/message-headers-field-arrays
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import datetime | ||
| import decimal | ||
| import typing | ||
| import unittest | ||
|
|
||
| import pydantic | ||
|
|
||
| from rejected import models | ||
|
|
||
|
|
||
| def _make_message(headers: typing.Any) -> models.Message: | ||
| return models.Message( | ||
| delivery_tag=1, | ||
| exchange='ex', | ||
| routing_key='k', | ||
| body=b'', | ||
| app_id=None, | ||
| content_encoding=None, | ||
| content_type=None, | ||
| correlation_id=None, | ||
| delivery_mode=None, | ||
| expiration=None, | ||
| headers=headers, | ||
| message_id=None, | ||
| type=None, | ||
| priority=None, | ||
| redelivered=False, | ||
| reply_to=None, | ||
| timestamp=None, | ||
| user_id=None, | ||
| ) | ||
|
|
||
|
|
||
| class MessageHeadersTestCase(unittest.TestCase): | ||
| def test_scalar_values(self) -> None: | ||
| headers = { | ||
| 'bool': True, | ||
| 'int': 1, | ||
| 'float': 1.5, | ||
| 'str': 'value', | ||
| 'bytes': b'value', | ||
| 'decimal': decimal.Decimal('1.5'), | ||
| 'timestamp': datetime.datetime.now(tz=datetime.UTC), | ||
| 'void': None, | ||
| } | ||
| self.assertEqual(_make_message(headers).headers, headers) | ||
|
|
||
| def test_nested_table(self) -> None: | ||
| headers = {'table': {'nested': {'key': 'value'}, 'count': 1}} | ||
| self.assertEqual(_make_message(headers).headers, headers) | ||
|
|
||
| def test_array_of_scalars(self) -> None: | ||
| headers = {'array': ['a', 1, True, None]} | ||
| self.assertEqual(_make_message(headers).headers, headers) | ||
|
|
||
| def test_x_death_array_of_tables(self) -> None: | ||
| """RabbitMQ sets ``x-death`` on every dead-lettered message as an | ||
| array of tables, which pika decodes to a list of dicts.""" | ||
| headers = { | ||
| 'x-death': [ | ||
| { | ||
| 'count': 1, | ||
| 'reason': 'rejected', | ||
| 'queue': 'q', | ||
| 'time': datetime.datetime.now(tz=datetime.UTC), | ||
| 'exchange': 'ex', | ||
| 'routing-keys': ['k'], | ||
| } | ||
| ], | ||
| 'x-first-death-exchange': 'ex', | ||
| 'x-first-death-queue': 'q', | ||
| 'x-first-death-reason': 'rejected', | ||
| } | ||
| self.assertEqual(_make_message(headers).headers, headers) | ||
|
|
||
| def test_empty_headers(self) -> None: | ||
| self.assertEqual(_make_message({}).headers, {}) | ||
|
|
||
| def test_non_dict_headers_rejected(self) -> None: | ||
| for value in (['x-death'], 'value', 1, None): | ||
| with self.subTest(value=value): | ||
| with self.assertRaises(pydantic.ValidationError): | ||
| _make_message(value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: gmr/rejected
Length of output: 5008
🏁 Script executed:
Repository: gmr/rejected
Length of output: 6762
Handle out-of-range timestamps in the invalid-property path.
When
properties.timestampis253402300800,datetime.datetime.fromtimestampcan raise a range-related exception before the currenttryblock. The delivery then bypasses the invalid-property rejection path. Move the conversion into the guarded block and catch its range errors.Suggested fix
🤖 Prompt for AI Agents