Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Added validation for timestamp comparison (#14025)
ritanjandawn0da7b42544f9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 79da0f8983..ee9ce747d0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,6 +21,7 @@ All notable, unreleased changes to this project will be documented in this file.### Other changes- Add transaction items deletion to cleardb command. - #14198 by @jakubkuc+- Added validation for timestamp comparison #14025 by @ritanjandawn# 3.17.0diff --git a/saleor/graphql/order/bulk_mutations/order_bulk_create.py b/saleor/graphql/order/bulk_mutations/order_bulk_create.pyindex d9075b180e..0f49f753c4 100644--- a/saleor/graphql/order/bulk_mutations/order_bulk_create.py+++ b/saleor/graphql/order/bulk_mutations/order_bulk_create.py@@ -747,7 +747,15 @@ class OrderBulkCreate(BaseMutation, I18nMixin):Some systems might have incorrect time that is in the future compared to Saleor.At the same time, we don't want to create orders that are too far in the future."""- return date < timezone.now() + timedelta(minutes=MINUTES_DIFF)+ current_time = timezone.now()+ future_time = current_time + timedelta(minutes=MINUTES_DIFF)+ if not date.tzinfo:+ raise ValidationError(+ message="Input 'date' must be timezone-aware. "+ "Expected format: 'YYYY-MM-DD HH:MM:SS TZ'.",+ code=OrderBulkCreateErrorCode.INVALID.value,+ )+ return date < future_time@classmethoddef is_shipping_required(cls, order_input: Dict[str, Any]) -> bool:diff --git a/saleor/graphql/order/tests/mutations/test_order_bulk_create.py b/saleor/graphql/order/tests/mutations/test_order_bulk_create.pyindex 6f29a4b45c..ee341bd895 100644--- a/saleor/graphql/order/tests/mutations/test_order_bulk_create.py+++ b/saleor/graphql/order/tests/mutations/test_order_bulk_create.py@@ -1,5 +1,5 @@import copy-from datetime import timedelta+from datetime import datetime, timedeltafrom decimal import Decimalfrom unittest.mock import patch@@ -257,6 +257,10 @@ ORDER_BULK_CREATE = """code}}+ errors {+ message+ code+ }}}"""@@ -1995,6 +1999,43 @@ def test_order_bulk_create_error_order_future_date(assert Order.objects.count() == orders_count+def test_order_bulk_create_invalid_date_format(+ staff_api_client,+ permission_manage_orders,+ permission_manage_orders_import,+ order_bulk_input,+):+ # given+ orders_count = Order.objects.count()++ order = order_bulk_input+ current_time = datetime.now() + timedelta(minutes=MINUTES_DIFF + 1)+ order["createdAt"] = current_time.strftime("%Y-%m-%dT%H:%M:%S")++ staff_api_client.user.user_permissions.add(+ permission_manage_orders_import,+ permission_manage_orders,+ )+ variables = {+ "orders": [order],+ "stockUpdatePolicy": StockUpdatePolicyEnum.SKIP.name,+ }++ # when+ response = staff_api_client.post_graphql(ORDER_BULK_CREATE, variables)+ content = get_graphql_content(response)++ # then+ error = content["data"]["orderBulkCreate"]["errors"][0]+ assert (+ error["message"] == "Input 'date' must be timezone-aware. "+ "Expected format: 'YYYY-MM-DD HH:MM:SS TZ'."+ )+ assert error["code"] == OrderBulkCreateErrorCode.INVALID.name++ assert Order.objects.count() == orders_count++def test_order_bulk_create_error_order_line_future_date(staff_api_client,permission_manage_orders,