This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Sqs/remove dynamic attrs for avro #13655
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
720a0cc
remove dynamic attrs from stored attrs
baermat 21bae92
adjust attribute selection
baermat c7281ed
add comments, fix imports
baermat 700456c
add comments
baermat 10528a0
work in suggestions
baermat 7467c04
fix string cast
baermat 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| TagMap, | ||
| ) | ||
| from localstack.services.sqs import constants as sqs_constants | ||
| from localstack.services.sqs.constants import APPROXIMATE_DYNAMIC_ATTRIBUTES | ||
| from localstack.services.sqs.exceptions import ( | ||
| InvalidAttributeValue, | ||
| InvalidParameterValueException, | ||
|
|
@@ -43,7 +44,7 @@ | |
| ) | ||
| from localstack.services.stores import AccountRegionBundle, BaseStore, LocalAttribute | ||
| from localstack.utils.aws.arns import get_partition | ||
| from localstack.utils.strings import long_uid | ||
| from localstack.utils.strings import camel_to_snake_case, long_uid | ||
| from localstack.utils.time import now | ||
| from localstack.utils.urls import localstack_host | ||
|
|
||
|
|
@@ -346,15 +347,6 @@ def shutdown(self): | |
|
|
||
| def default_attributes(self) -> QueueAttributeMap: | ||
| return { | ||
| QueueAttributeName.ApproximateNumberOfMessages: lambda: str( | ||
| self.approx_number_of_messages | ||
| ), | ||
| QueueAttributeName.ApproximateNumberOfMessagesNotVisible: lambda: str( | ||
| self.approx_number_of_messages_not_visible | ||
| ), | ||
| QueueAttributeName.ApproximateNumberOfMessagesDelayed: lambda: str( | ||
| self.approx_number_of_messages_delayed | ||
| ), | ||
| QueueAttributeName.CreatedTimestamp: str(now()), | ||
| QueueAttributeName.DelaySeconds: "0", | ||
| QueueAttributeName.LastModifiedTimestamp: str(now()), | ||
|
|
@@ -473,15 +465,15 @@ def maximum_message_size(self) -> int: | |
| return int(self.attributes[QueueAttributeName.MaximumMessageSize]) | ||
|
|
||
| @property | ||
| def approx_number_of_messages(self) -> int: | ||
| def approximate_number_of_messages(self) -> int: | ||
| raise NotImplementedError | ||
|
|
||
| @property | ||
| def approx_number_of_messages_not_visible(self) -> int: | ||
| def approximate_number_of_messages_not_visible(self) -> int: | ||
| return len(self.inflight) | ||
|
|
||
| @property | ||
| def approx_number_of_messages_delayed(self) -> int: | ||
| def approximate_number_of_messages_delayed(self) -> int: | ||
| return len(self.delayed) | ||
|
|
||
| def validate_receipt_handle(self, receipt_handle: str): | ||
|
|
@@ -724,7 +716,7 @@ def get_queue_attributes(self, attribute_names: AttributeNameList = None) -> dic | |
| return {} | ||
|
|
||
| if QueueAttributeName.All in attribute_names: | ||
| attribute_names = self.attributes.keys() | ||
| attribute_names = list(self.attributes.keys()) + APPROXIMATE_DYNAMIC_ATTRIBUTES | ||
|
|
||
| result: dict[QueueAttributeName, str] = {} | ||
|
|
||
|
|
@@ -734,13 +726,13 @@ def get_queue_attributes(self, attribute_names: AttributeNameList = None) -> dic | |
| except AttributeError: | ||
| raise InvalidAttributeName(f"Unknown Attribute {attr}.") | ||
|
|
||
| value = self.attributes.get(attr) | ||
| if callable(value): | ||
| func = value | ||
| value = func() | ||
| if value is not None: | ||
| result[attr] = value | ||
| elif value == "False" or value == "True": | ||
| if attr in APPROXIMATE_DYNAMIC_ATTRIBUTES: | ||
| # The approximate_* attributes are calculated on the spot when accessed. | ||
| # We have a @property for each of those which calculates the value. | ||
| value = str(getattr(self, camel_to_snake_case(attr))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think i would prefer a less magical approach and just have a match/case block. this way we know where the properties are being access: something like result: dict[QueueAttributeName, str] = {}
for attr in attribute_names:
try:
getattr(QueueAttributeName, attr)
except AttributeError:
raise InvalidAttributeName(f"Unknown Attribute {attr}.")
value = None
match attr:
case QueueAttributeName.ApproximateNumberOfMessages:
value = self.approx_number_of_messages
case QueueAttributeName.ApproximateNumberOfMessagesDelayed:
value = ...
case _:
value = self.attributes.get(attr)
if value == "False" or value == "True":
result[attr] = value.lower()
elif value is not None:
result[attr] = value
return result
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do, and yes, it is definitely simpler this way. I guess I couldn't resist the magical approach 😃 |
||
| else: | ||
| value = self.attributes.get(attr) | ||
| if value == "False" or value == "True": | ||
| result[attr] = value.lower() | ||
| elif value is not None: | ||
| result[attr] = value | ||
|
|
@@ -799,7 +791,7 @@ def clear(self): | |
| self.visible.queue.clear() | ||
|
|
||
| @property | ||
| def approx_number_of_messages(self): | ||
| def approximate_number_of_messages(self): | ||
| return self.visible.qsize() | ||
|
|
||
| def shutdown(self): | ||
|
|
@@ -1025,7 +1017,7 @@ def __init__(self, name: str, region: str, account_id: str, attributes=None, tag | |
| self.deduplication_scope = self.attributes[QueueAttributeName.DeduplicationScope] | ||
|
|
||
| @property | ||
| def approx_number_of_messages(self): | ||
| def approximate_number_of_messages(self): | ||
| n = 0 | ||
| for message_group in self.message_groups.values(): | ||
| n += len(message_group.messages) | ||
|
|
||
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
Oops, something went wrong.
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.
maybe just call it
DYNAMIC_ATTRIBUTES?