Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix situation when Payment Gateway try to save to long error message. (#10402)

Filip Owczareke60cf03c4e34
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 93fe0b7cce..4d44473807 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable, unreleased changes to this project will be documented in this file.
# 3.7.0 [Unreleased]
+### Other changes
+- Fix situation when Payment Gateway try to save to long error message - #10402 by @fowczarek
+
# 3.6.0
### Breaking changes
diff --git a/saleor/payment/migrations/0037_alter_transaction_error.py b/saleor/payment/migrations/0037_alter_transaction_error.py
new file mode 100644
index 0000000000..5fedc7f0d3
--- /dev/null
+++ b/saleor/payment/migrations/0037_alter_transaction_error.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.15 on 2022-08-16 10:52
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("payment", "0036_auto_20220518_0732"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="transaction",
+ name="error",
+ field=models.TextField(null=True),
+ ),
+ ]
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index 27dd8c4f19..2b96dc6eaf 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -326,10 +326,7 @@ class Transaction(models.Model):
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
default=Decimal("0.0"),
)
- error = models.CharField(
- max_length=256,
- null=True,
- )
+ error = models.TextField(null=True)
customer_id = models.CharField(max_length=256, null=True)
gateway_response = JSONField(encoder=DjangoJSONEncoder)
already_processed = models.BooleanField(default=False)
diff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.py
index 411e7865fe..26cccdc517 100644
--- a/saleor/payment/tests/test_payment.py
+++ b/saleor/payment/tests/test_payment.py
@@ -80,6 +80,19 @@ def transaction_data(payment_dummy, gateway_response):
}
+def transaction_data_long_error_message(payment_dummy):
+ error_msg = "This is very very long response from payment gateway. " * 10
+ return {
+ "payment": payment_dummy,
+ "payment_information": create_payment_information(
+ payment_dummy, "payment-token"
+ ),
+ "error_msg": error_msg,
+ "kind": TransactionKind.CAPTURE_FAILED,
+ }
+
+
@pytest.fixture
def transaction_token():
return "transaction-token"
@@ -397,6 +410,14 @@ def test_create_transaction(transaction_data):
assert txn.gateway_response == gateway_response.raw_response
+def test_create_transaction_long_error_message(transaction_data_long_error_message):
+ transaction_data = transaction_data_long_error_message
+ txn = create_transaction(**transaction_data)
+
+ assert txn.payment == transaction_data["payment"]
+ assert txn.error == transaction_data["error_msg"]
+
+
def test_create_transaction_no_gateway_response(transaction_data):
transaction_data.pop("gateway_response")
txn = create_transaction(**transaction_data)