Skip to content

Commit

Permalink
adds deprecation warnings for using message_protocol keyword and attr…
Browse files Browse the repository at this point in the history
…ibute + fixes awssnssqs decorator signature
  • Loading branch information
kalaspuff committed Aug 8, 2023
1 parent 52e6a67 commit 34d3e7a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tomodachi/transport/aws_sns_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import string
import time
import uuid
import warnings
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -215,12 +216,23 @@ async def publish(
# Fallback if deprecated message_protocol keyword is used
message_envelope = message_protocol

warnings.warn(
"Using the 'message_protocol' keyword argument is deprecated. Use 'message_envelope' instead.",
DeprecationWarning,
)

message_envelope = (
getattr(service, "message_envelope", getattr(service, "message_protocol", None))
if message_envelope == MESSAGE_ENVELOPE_DEFAULT
else message_envelope
)

if getattr(service, "message_protocol", None):
warnings.warn(
"Using the 'message_protocol' attribute on a service is deprecated. Use 'message_envelope' instead.",
DeprecationWarning,
)

if not message_attributes:
message_attributes = {}
else:
Expand Down Expand Up @@ -400,12 +412,23 @@ async def subscribe_handler(
# Fallback if deprecated message_protocol keyword is used
message_envelope = message_protocol

warnings.warn(
"Using the 'message_protocol' keyword argument is deprecated. Use 'message_envelope' instead.",
DeprecationWarning,
)

message_envelope = (
context.get("message_envelope", context.get("message_protocol"))
if message_envelope == MESSAGE_ENVELOPE_DEFAULT
else message_envelope
)

if context.get("message_protocol"):
warnings.warn(
"Using the 'message_protocol' attribute on a service is deprecated. Use 'message_envelope' instead.",
DeprecationWarning,
)

# Validate the parser kwargs if there is a validation function in the envelope
if message_envelope:
envelope_kwargs_validation_func = getattr(message_envelope, "validate", None)
Expand Down Expand Up @@ -2038,6 +2061,11 @@ def aws_sns_sqs(
message_envelope: Any = MESSAGE_ENVELOPE_DEFAULT,
message_protocol: Any = MESSAGE_ENVELOPE_DEFAULT, # deprecated
filter_policy: Optional[Union[str, FilterPolicyDictType]] = FILTER_POLICY_DEFAULT,
visibility_timeout: Optional[int] = VISIBILITY_TIMEOUT_DEFAULT,
dead_letter_queue_name: Optional[str] = DEAD_LETTER_QUEUE_DEFAULT,
max_receive_count: Optional[int] = MAX_RECEIVE_COUNT_DEFAULT,
fifo: bool = False,
max_number_of_consumed_messages: Optional[int] = MAX_NUMBER_OF_CONSUMED_MESSAGES,
**kwargs: Any,
) -> Callable:
return cast(
Expand All @@ -2050,6 +2078,11 @@ def aws_sns_sqs(
message_envelope=message_envelope,
message_protocol=message_protocol,
filter_policy=filter_policy,
visibility_timeout=visibility_timeout,
dead_letter_queue_name=dead_letter_queue_name,
max_receive_count=max_receive_count,
fifo=fifo,
max_number_of_consumed_messages=max_number_of_consumed_messages,
**kwargs,
),
)
Expand All @@ -2064,6 +2097,11 @@ def awssnssqs(
message_envelope: Any = MESSAGE_ENVELOPE_DEFAULT,
message_protocol: Any = MESSAGE_ENVELOPE_DEFAULT, # deprecated
filter_policy: Optional[Union[str, FilterPolicyDictType]] = FILTER_POLICY_DEFAULT,
visibility_timeout: Optional[int] = VISIBILITY_TIMEOUT_DEFAULT,
dead_letter_queue_name: Optional[str] = DEAD_LETTER_QUEUE_DEFAULT,
max_receive_count: Optional[int] = MAX_RECEIVE_COUNT_DEFAULT,
fifo: bool = False,
max_number_of_consumed_messages: Optional[int] = MAX_NUMBER_OF_CONSUMED_MESSAGES,
**kwargs: Any,
) -> Callable:
return cast(
Expand All @@ -2076,6 +2114,11 @@ def awssnssqs(
message_envelope=message_envelope,
message_protocol=message_protocol,
filter_policy=filter_policy,
visibility_timeout=visibility_timeout,
dead_letter_queue_name=dead_letter_queue_name,
max_receive_count=max_receive_count,
fifo=fifo,
max_number_of_consumed_messages=max_number_of_consumed_messages,
**kwargs,
),
)

0 comments on commit 34d3e7a

Please sign in to comment.