2424 TagMap ,
2525)
2626from localstack .services .sqs import constants as sqs_constants
27+ from localstack .services .sqs .constants import DYNAMIC_ATTRIBUTES
2728from localstack .services .sqs .exceptions import (
2829 InvalidAttributeValue ,
2930 InvalidParameterValueException ,
@@ -346,15 +347,6 @@ def shutdown(self):
346347
347348 def default_attributes (self ) -> QueueAttributeMap :
348349 return {
349- QueueAttributeName .ApproximateNumberOfMessages : lambda : str (
350- self .approx_number_of_messages
351- ),
352- QueueAttributeName .ApproximateNumberOfMessagesNotVisible : lambda : str (
353- self .approx_number_of_messages_not_visible
354- ),
355- QueueAttributeName .ApproximateNumberOfMessagesDelayed : lambda : str (
356- self .approx_number_of_messages_delayed
357- ),
358350 QueueAttributeName .CreatedTimestamp : str (now ()),
359351 QueueAttributeName .DelaySeconds : "0" ,
360352 QueueAttributeName .LastModifiedTimestamp : str (now ()),
@@ -473,15 +465,15 @@ def maximum_message_size(self) -> int:
473465 return int (self .attributes [QueueAttributeName .MaximumMessageSize ])
474466
475467 @property
476- def approx_number_of_messages (self ) -> int :
468+ def approximate_number_of_messages (self ) -> int :
477469 raise NotImplementedError
478470
479471 @property
480- def approx_number_of_messages_not_visible (self ) -> int :
472+ def approximate_number_of_messages_not_visible (self ) -> int :
481473 return len (self .inflight )
482474
483475 @property
484- def approx_number_of_messages_delayed (self ) -> int :
476+ def approximate_number_of_messages_delayed (self ) -> int :
485477 return len (self .delayed )
486478
487479 def validate_receipt_handle (self , receipt_handle : str ):
@@ -724,7 +716,7 @@ def get_queue_attributes(self, attribute_names: AttributeNameList = None) -> dic
724716 return {}
725717
726718 if QueueAttributeName .All in attribute_names :
727- attribute_names = self .attributes .keys ()
719+ attribute_names = list ( self .attributes .keys ()) + DYNAMIC_ATTRIBUTES
728720
729721 result : dict [QueueAttributeName , str ] = {}
730722
@@ -734,13 +726,18 @@ def get_queue_attributes(self, attribute_names: AttributeNameList = None) -> dic
734726 except AttributeError :
735727 raise InvalidAttributeName (f"Unknown Attribute { attr } ." )
736728
737- value = self .attributes .get (attr )
738- if callable (value ):
739- func = value
740- value = func ()
741- if value is not None :
742- result [attr ] = value
743- elif value == "False" or value == "True" :
729+ # The approximate_* attributes are calculated on the spot when accessed.
730+ # We have a @property for each of those which calculates the value.
731+ match attr :
732+ case QueueAttributeName .ApproximateNumberOfMessages :
733+ value = str (self .approximate_number_of_messages )
734+ case QueueAttributeName .ApproximateNumberOfMessagesDelayed :
735+ value = str (self .approximate_number_of_messages_delayed )
736+ case QueueAttributeName .ApproximateNumberOfMessagesNotVisible :
737+ value = str (self .approximate_number_of_messages_not_visible )
738+ case _:
739+ value = self .attributes .get (attr )
740+ if value == "False" or value == "True" :
744741 result [attr ] = value .lower ()
745742 elif value is not None :
746743 result [attr ] = value
@@ -799,7 +796,7 @@ def clear(self):
799796 self .visible .queue .clear ()
800797
801798 @property
802- def approx_number_of_messages (self ):
799+ def approximate_number_of_messages (self ):
803800 return self .visible .qsize ()
804801
805802 def shutdown (self ):
@@ -1025,7 +1022,7 @@ def __init__(self, name: str, region: str, account_id: str, attributes=None, tag
10251022 self .deduplication_scope = self .attributes [QueueAttributeName .DeduplicationScope ]
10261023
10271024 @property
1028- def approx_number_of_messages (self ):
1025+ def approximate_number_of_messages (self ):
10291026 n = 0
10301027 for message_group in self .message_groups .values ():
10311028 n += len (message_group .messages )
0 commit comments