-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fix internal server error on too long input for transaction create and update mutation #13608
base: main
Are you sure you want to change the base?
Changes from 5 commits
b4771aa
291775b
1169cc9
b8a8445
f3b5cb8
be7e04f
7e5442f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,33 +97,49 @@ def check_can_update( | |
|
||
@classmethod | ||
def validate_transaction_input( | ||
cls, instance: payment_models.TransactionItem, transaction_data | ||
cls, | ||
instance: payment_models.TransactionItem, | ||
transaction_data, | ||
transaction_event_data | ||
Comment on lines
+113
to
+114
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. Maybe it's just a small nitpick - the first mutation uses |
||
): | ||
currency = instance.currency | ||
if transaction_data.get("available_actions") is not None: | ||
transaction_data["available_actions"] = list( | ||
set(transaction_data.get("available_actions", [])) | ||
) | ||
|
||
cls.validate_money_input( | ||
transaction_data, | ||
currency, | ||
TransactionUpdateErrorCode.INCORRECT_CURRENCY.value, | ||
) | ||
cls.validate_metadata_keys( | ||
transaction_data.get("metadata", []), | ||
field_name="metadata", | ||
error_code=TransactionUpdateErrorCode.METADATA_KEY_REQUIRED.value, | ||
) | ||
cls.validate_metadata_keys( | ||
transaction_data.get("private_metadata", []), | ||
field_name="privateMetadata", | ||
error_code=TransactionUpdateErrorCode.METADATA_KEY_REQUIRED.value, | ||
) | ||
cls.validate_external_url( | ||
transaction_data.get("external_url"), | ||
error_code=TransactionCreateErrorCode.INVALID.value, | ||
) | ||
|
||
if transaction_data: | ||
cls.validate_psp_reference( | ||
transaction_data.get("psp_reference"), | ||
field_name="transaction", | ||
error_code=TransactionUpdateErrorCode.INVALID.value, | ||
) | ||
cls.validate_money_input( | ||
transaction_data, | ||
currency, | ||
TransactionUpdateErrorCode.INCORRECT_CURRENCY.value, | ||
) | ||
cls.validate_metadata_keys( | ||
transaction_data.get("metadata", []), | ||
field_name="metadata", | ||
error_code=TransactionUpdateErrorCode.METADATA_KEY_REQUIRED.value, | ||
) | ||
cls.validate_metadata_keys( | ||
transaction_data.get("private_metadata", []), | ||
field_name="privateMetadata", | ||
error_code=TransactionUpdateErrorCode.METADATA_KEY_REQUIRED.value, | ||
) | ||
cls.validate_external_url( | ||
transaction_data.get("external_url"), | ||
error_code=TransactionCreateErrorCode.INVALID.value, | ||
) | ||
if transaction_event_data: | ||
cls.validate_psp_reference( | ||
transaction_event_data.get("psp_reference"), | ||
field_name="transactionEvent", | ||
error_code=TransactionUpdateErrorCode.INVALID.value, | ||
) | ||
|
||
@classmethod | ||
def update_transaction( | ||
|
@@ -200,8 +216,9 @@ def perform_mutation( # type: ignore[override] | |
previous_charged_value = instance.charged_value | ||
previous_refunded_value = instance.refunded_value | ||
|
||
cls.validate_transaction_input(instance, transaction, transaction_event) | ||
|
||
if transaction: | ||
cls.validate_transaction_input(instance, transaction) | ||
cls.assign_app_to_transaction_data_if_missing(instance, transaction, app) | ||
cls.cleanup_metadata_data(transaction) | ||
money_data = cls.get_money_data_from_input(transaction) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -834,6 +834,12 @@ def parse_transaction_action_data( | |
logger.error(msg) | ||
return None, msg | ||
|
||
if psp_reference: | ||
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. you could make it as a single condition: if psp_reference and len(psp_reference) > 512:
... |
||
if len(psp_reference) > 512: | ||
msg: str = "Maximum length for `pspReference` is 512." | ||
logger.error(msg) | ||
return None, msg | ||
|
||
available_actions = response_data.get("actions", None) | ||
if available_actions is not None: | ||
possible_actions = { | ||
|
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.
We would have to move this entry to the newest version section - 3.18.
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.
We already moved forward with releases so when you fix this please move this to 3.19 (or just the newest unreleased version in the CHANGELOG.md)