Skip to content

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

Deprecate `EU` from `CountryCode` enum (#16301)

Iga Karbowiakd39d35a1ba47
diff --git a/.github/workflows/publish-containers.yml b/.github/workflows/publish-containers.yml
index f2c09d13a7..fd5980f748 100644
--- a/.github/workflows/publish-containers.yml
+++ b/.github/workflows/publish-containers.yml
@@ -22,7 +22,7 @@ jobs:
permissions:
contents: read
packages: write
-
+
outputs:
version: ${{ steps.meta.outputs.version }}
diff --git a/saleor/graphql/account/enums.py b/saleor/graphql/account/enums.py
index d642f9e29e..60fbd6c47f 100644
--- a/saleor/graphql/account/enums.py
+++ b/saleor/graphql/account/enums.py
@@ -15,7 +15,12 @@ CustomerEventsEnum.doc_category = DOC_CATEGORY_USERS
CountryCodeEnum = graphene.Enum(
- "CountryCode", [(str_to_enum(country[0]), country[0]) for country in countries]
+ "CountryCode",
+ [(str_to_enum(country[0]), country[0]) for country in countries],
+ description=(
+ "Represents country codes defined by the ISO 3166-1 alpha-2 standard."
+ "\n\nThe `EU` value is DEPRECATED and will be removed in Saleor 3.21."
+ ),
)
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.py
index ab1ec5fc5a..6212345fda 100644
--- a/saleor/graphql/account/resolvers.py
+++ b/saleor/graphql/account/resolvers.py
@@ -2,6 +2,7 @@ from itertools import chain
from typing import Optional
from django.db.models import Q
+from graphql import GraphQLError
from i18naddress import get_validation_rules
from ...account import models
@@ -149,6 +150,10 @@ def resolve_address_validation_rules(
"city": city,
"city_area": city_area,
}
+ # EU is available as a country code in CountryCode enum but it's not valid for
+ # the address validation
+ if country_code.upper() == "EU":
+ raise GraphQLError("Cannot validate address for EU country code.")
rules = get_validation_rules(params)
return AddressValidationData(
country_code=rules.country_code,
diff --git a/saleor/graphql/account/tests/queries/test_address_validation_rules.py b/saleor/graphql/account/tests/queries/test_address_validation_rules.py
index faaed67da7..1fd58c1837 100644
--- a/saleor/graphql/account/tests/queries/test_address_validation_rules.py
+++ b/saleor/graphql/account/tests/queries/test_address_validation_rules.py
@@ -1,6 +1,6 @@
import re
-from ....tests.utils import get_graphql_content
+from ....tests.utils import assert_graphql_error_with_message, get_graphql_content
GET_ADDRESS_VALIDATION_RULES_QUERY = """
query getValidator(
@@ -113,6 +113,20 @@ def test_address_validation_rules_with_country_area(user_api_client):
assert set(data["upperFields"]) == {"countryArea"}
+def test_address_validation_rules_for_EU(user_api_client):
+ # given
+ query = GET_ADDRESS_VALIDATION_RULES_QUERY
+ variables = {"country_code": "EU", "country_area": None, "city_area": None}
+
+ # when
+ response = user_api_client.post_graphql(query, variables)
+
+ # then
+ assert_graphql_error_with_message(
+ response, "Cannot validate address for EU country code."
+ )
+
+
def test_address_validation_rules_fields_in_camel_case(user_api_client):
query = """
query getValidator(
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 7b2a263d2a..0c5d61e12c 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -5264,7 +5264,11 @@ type ShippingMethodsPerCountry @doc(category: "Shipping") {
shippingMethods: [ShippingMethod!]
}
-"""An enumeration."""
+"""
+Represents country codes defined by the ISO 3166-1 alpha-2 standard.
+
+The `EU` value is DEPRECATED and will be removed in Saleor 3.21.
+"""
enum CountryCode {
AF
AX