-
Notifications
You must be signed in to change notification settings - Fork 403
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
Feature request: Return empty Dict or List in Event Source Data Classes instead of None #2605
Comments
Hi @ericbn thank you for sending this proposal! Two notes:
It seems to be this would be a big breaking change anyways. So we might have to open an RFC to discuss this with the larger community and consider the breaking change for v3. |
Hi. Totally agree this is a breaking change for existing code that relies on None as a valid value. Good point. I see the change in the headers method in BaseProxyEvent was done exactly to keep backward compatibility. I propose this change is favor of an API with multiple methods like get_query_string_value and get_header_value in BaseProxyEvent. powertools-lambda-python/aws_lambda_powertools/utilities/data_classes/common.py Lines 139 to 157 in 2c44207
powertools-lambda-python/aws_lambda_powertools/utilities/data_classes/common.py Lines 159 to 186 in 2c44207
Pros:
Cons(?):
|
Hello @ericbn! We've updated our roadmap and included this feature request. We are planning to release this feature in Powertools v3. Roadmap for v3: https://docs.powertools.aws.dev/lambda/python/latest/roadmap/#v3 |
Hi @leandrodamascena, cool! I'll be happy to provide a PR if that sounds good. Thanks for considering and accepting the feature request! |
Hello @ericbn! We definitely want you to submit a PR and contribute to the project, this idea of yours brings more consistency to the use of a data class. I just would like to ask is that you wait until we create the Powertools v3 RFC and have the plan defined. If you send the PR now it will take a long time without updating and it will be hard to merge in the future. I created a new label Thank you. |
Sure, I’ll wait. Makes perfect sense. Looking forward for my first contribution with a PR to the project! |
Took a long time (stability/backwards compatibility) but we've started implementing for v3: #4189 |
Oi @heitorlessa. I'll be happy to work on this as a contribution to the project. |
Closed via #4606 |
|
Use case
Arguably, it might be easier for users if an empty Dict is returned instead of
None
for path_parameters in APIGatewayProxyEventV2, for example.Instead of:
it would become:
Ultimately this approach could be followed for any return value that is either an Optional[Dict] or an Optional[List], returning an empty Dict or List instead of
None
in all cases:def claims(self) -> Dict[str, Any]
def scopes(self) -> List[str]
def multi_value_query_string_parameters(self) -> Dict[str, List[str]]
def path_parameters(self) -> Dict[str, str]
def stage_variables(self) -> Dict[str, str]
def cognito_amr(self) -> List[str]
def jwt_claim(self) -> Dict[str, Any]
def jwt_scopes(self) -> List[str]
def get_lambda(self) -> Dict[str, Any]
def cookies(self) -> List[str]
def path_parameters(self) -> Dict[str, str]
def stage_variables(self) -> Dict[str, str]
and so on...
The bottom line is: Does it matter for users to differentiate between
None
and an empty Dict or List for any Event Source Data Classe property? If it does for a particular one, it an exception to a rule or the rule?This change would be backwards compatible with the previous code.
This approach was already implemented in only one place so far, as far as I could check:
def headers(self) -> Dict[str, str]
Solution/User Experience
Solution can be the same as for the headers in the BaseProxyEvent:
powertools-lambda-python/aws_lambda_powertools/utilities/data_classes/common.py
Lines 98 to 100 in 1905e4c
Alternative solutions
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: