Skip to content

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

Update description/content to return null (#6860)

Damian Wysocki308cd60c6e4b
diff --git a/saleor/core/utils/editorjs.py b/saleor/core/utils/editorjs.py
index 75166d92b0..0b1966deef 100644
--- a/saleor/core/utils/editorjs.py
+++ b/saleor/core/utils/editorjs.py
@@ -1,5 +1,6 @@
import re
import warnings
+from typing import Dict, Optional
from urllib3.util import parse_url
@@ -7,7 +8,7 @@ BLACKLISTED_URL_SCHEMES = ("javascript",)
HYPERLINK_TAG_WITH_URL_PATTERN = r"(.*?<a\s+href=\\?\")(\w+://\S+[^\\])(\\?\">)"
-def clean_editor_js(definitions: dict, *, to_string: bool = False):
+def clean_editor_js(definitions: Optional[Dict], *, to_string: bool = False):
"""Sanitize a given EditorJS JSON definitions.
Look for not allowed URLs, replaced them with `invalid` value, and clean valid ones.
@@ -16,6 +17,10 @@ def clean_editor_js(definitions: dict, *, to_string: bool = False):
instead of returning json object.
"""
string = ""
+
+ if definitions is None:
+ return string if to_string else definitions
+
blocks = definitions.get("blocks")
if not blocks or not isinstance(blocks, list):
diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.py
index f01d08077b..ccd4bbe133 100644
--- a/saleor/graphql/page/types.py
+++ b/saleor/graphql/page/types.py
@@ -61,7 +61,8 @@ class Page(CountableDjangoObjectType):
@staticmethod
def resolve_content_json(root: models.Page, info):
- return root.content
+ content = root.content
+ return content if content is not None else {}
@staticmethod
def resolve_attributes(root: models.Page, info):
diff --git a/saleor/graphql/product/tests/test_category.py b/saleor/graphql/product/tests/test_category.py
index 111b5b3573..a477665243 100644
--- a/saleor/graphql/product/tests/test_category.py
+++ b/saleor/graphql/product/tests/test_category.py
@@ -90,6 +90,33 @@ def test_category_query_description(user_api_client, product, channel_USD):
assert category_data["descriptionJson"] == description
+def test_category_query_without_description(user_api_client, product, channel_USD):
+ category = Category.objects.first()
+ category.save()
+ variables = {
+ "id": graphene.Node.to_global_id("Category", category.pk),
+ "channel": channel_USD.slug,
+ }
+ query = """
+ query ($id: ID, $slug: String){
+ category(
+ id: $id,
+ slug: $slug,
+ ) {
+ id
+ name
+ description
+ descriptionJson
+ }
+ }
+ """
+ response = user_api_client.post_graphql(query, variables=variables)
+ content = get_graphql_content(response)
+ category_data = content["data"]["category"]
+ assert category_data["description"] is None
+ assert category_data["descriptionJson"] == "{}"
+
+
def test_category_query_by_slug(user_api_client, product, channel_USD):
category = Category.objects.first()
variables = {"slug": category.slug, "channel": channel_USD.slug}
diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.py
index c5335bb73c..c0157a5d7a 100644
--- a/saleor/graphql/product/tests/test_collection.py
+++ b/saleor/graphql/product/tests/test_collection.py
@@ -181,6 +181,44 @@ def test_collections_query(
)
+def test_collections_query_without_description(
+ user_api_client,
+ published_collection,
+ unpublished_collection,
+ permission_manage_products,
+ channel_USD,
+):
+ query = """
+ query Collections ($channel: String) {
+ collections(first:2, channel: $channel) {
+ edges {
+ node {
+ name
+ slug
+ description
+ descriptionJson
+ }
+ }
+ }
+ }
+ """
+
+ # query public collections only as regular user
+ variables = {"channel": channel_USD.slug}
+ collection = published_collection
+ collection.description = None
+ collection.save()
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ edges = content["data"]["collections"]["edges"]
+ assert len(edges) == 1
+ collection_data = edges[0]["node"]
+ assert collection_data["name"] == collection.name
+ assert collection_data["slug"] == collection.slug
+ assert collection_data["description"] is None
+ assert collection_data["descriptionJson"] == "{}"
+
+
def test_collections_query_as_staff(
staff_api_client,
published_collection,
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.py
index 639e4bac30..caf5ddc138 100644
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@ -219,6 +219,41 @@ def test_product_query_description(
assert product_data["descriptionJson"] == description
+def test_product_query_with_no_description(
+ staff_api_client, permission_manage_products, product, channel_USD
+):
+ query = """
+ query ($id: ID, $slug: String, $channel:String){
+ product(
+ id: $id,
+ slug: $slug,
+ channel: $channel
+ ) {
+ id
+ name
+ description
+ descriptionJson
+ }
+ }
+ """
+ variables = {
+ "id": graphene.Node.to_global_id("Product", product.pk),
+ "channel": channel_USD.slug,
+ }
+
+ response = staff_api_client.post_graphql(
+ query,
+ variables=variables,
+ permissions=(permission_manage_products,),
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+ product_data = content["data"]["product"]
+ assert product_data is not None
+ assert product_data["description"] is None
+ assert product_data["descriptionJson"] == "{}"
+
+
def test_product_query_by_id_not_available_as_staff_user(
staff_api_client, permission_manage_products, product, channel_USD
):
@@ -3878,7 +3913,7 @@ def test_update_product_without_description_clear_description_plaintext(
assert not data["productErrors"]
assert data["product"]["name"] == product_name
assert data["product"]["slug"] == product_slug
- assert data["product"]["description"] == "{}"
+ assert data["product"]["description"] is None
product.refresh_from_db()
assert product.description_plaintext == ""
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index efccc0894b..88ed5463d6 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -590,7 +590,8 @@ class Product(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
@staticmethod
def resolve_description_json(root: ChannelContext[models.Product], info):
- return root.node.description
+ description = root.node.description
+ return description if description is not None else {}
@staticmethod
def resolve_tax_type(root: ChannelContext[models.Product], info):
@@ -1013,7 +1014,8 @@ class Collection(ChannelContextTypeWithMetadata, CountableDjangoObjectType):
@staticmethod
def resolve_description_json(root: ChannelContext[models.Collection], info):
- return root.node.description
+ description = root.node.description
+ return description if description is not None else {}
@key(fields="id")
@@ -1071,7 +1073,8 @@ class Category(CountableDjangoObjectType):
@staticmethod
def resolve_description_json(root: models.Category, info):
- return root.description
+ description = root.description
+ return description if description is not None else {}
@staticmethod
def resolve_background_image(root: models.Category, info, size=None, **_kwargs):
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index e82c2e7947..d497db28f1 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -671,7 +671,7 @@ type Category implements Node & ObjectWithMetadata {
seoDescription: String
id: ID!
name: String!
- description: JSONString!
+ description: JSONString
slug: String!
parent: Category
level: Int!
@@ -746,7 +746,7 @@ type CategoryTranslatableContent implements Node {
seoDescription: String
id: ID!
name: String!
- description: JSONString!
+ description: JSONString
descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")
translation(languageCode: LanguageCodeEnum!): CategoryTranslation
category: Category
@@ -763,7 +763,7 @@ type CategoryTranslation implements Node {
seoDescription: String
id: ID!
name: String!
- description: JSONString!
+ description: JSONString
language: LanguageDisplay!
descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")
}
@@ -1050,7 +1050,7 @@ type Collection implements Node & ObjectWithMetadata {
seoDescription: String
id: ID!
name: String!
- description: JSONString!
+ description: JSONString
slug: String!
privateMetadata: [MetadataItem]!
metadata: [MetadataItem]!
@@ -1205,7 +1205,7 @@ type CollectionTranslatableContent implements Node {
seoDescription: String
id: ID!
name: String!
- description: JSONString!
+ description: JSONString
descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")
translation(languageCode: LanguageCodeEnum!): CollectionTranslation
collection: Collection
@@ -1222,7 +1222,7 @@ type CollectionTranslation implements Node {
seoDescription: String
id: ID!
name: String!
- description: JSONString!
+ description: JSONString
language: LanguageDisplay!
descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")
}
@@ -3307,7 +3307,7 @@ type Page implements Node & ObjectWithMetadata {
seoDescription: String
id: ID!
title: String!
- content: JSONString!
+ content: JSONString
publicationDate: Date
isPublished: Boolean!
slug: String!
@@ -3441,7 +3441,7 @@ type PageTranslatableContent implements Node {
seoDescription: String
id: ID!
title: String!
- content: JSONString!
+ content: JSONString
contentJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.")
translation(languageCode: LanguageCodeEnum!): PageTranslation
page: Page
@@ -3458,7 +3458,7 @@ type PageTranslation implements Node {
seoDescription: String
id: ID!
title: String!
- content: JSONString!
+ content: JSONString
language: LanguageDisplay!
contentJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.")
}
@@ -3834,7 +3834,7 @@ type Product implements Node & ObjectWithMetadata {
seoTitle: String
seoDescription: String
name: String!
- description: JSONString!
+ description: JSONString
productType: ProductType!
slug: String!
category: Category
@@ -4140,7 +4140,7 @@ type ProductTranslatableContent implements Node {
seoTitle: String
seoDescription: String
name: String!
- description: JSONString!
+ description: JSONString
descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")
translation(languageCode: LanguageCodeEnum!): ProductTranslation
product: Product
@@ -4157,7 +4157,7 @@ type ProductTranslation implements Node {
seoTitle: String
seoDescription: String
name: String!
- description: JSONString!
+ description: JSONString
language: LanguageDisplay!
descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")
}
diff --git a/saleor/graphql/translations/tests/test_translations.py b/saleor/graphql/translations/tests/test_translations.py
index 83811bfaf9..f36b569646 100644
--- a/saleor/graphql/translations/tests/test_translations.py
+++ b/saleor/graphql/translations/tests/test_translations.py
@@ -45,6 +45,37 @@ def test_product_translation(user_api_client, product, channel_USD):
)
+def test_product_translation_without_description(user_api_client, product, channel_USD):
+ product.translations.create(language_code="pl", name="Produkt")
+
+ query = """
+ query productById($productId: ID!, $channel: String) {
+ product(id: $productId, channel: $channel) {
+ translation(languageCode: PL) {
+ name
+ description
+ descriptionJson
+ language {
+ code
+ }
+ }
+ }
+ }
+ """
+
+ product_id = graphene.Node.to_global_id("Product", product.id)
+ response = user_api_client.post_graphql(
+ query, {"productId": product_id, "channel": channel_USD.slug}
+ )
+ data = get_graphql_content(response)["data"]
+
+ translation_data = data["product"]["translation"]
+ assert translation_data["name"] == "Produkt"
+ assert translation_data["language"]["code"] == "PL"
+ assert translation_data["description"] is None
+ assert translation_data["descriptionJson"] == "{}"
+
+
def test_product_translation_with_app(app_api_client, product, channel_USD):
product.translations.create(language_code="pl", name="Produkt")
@@ -133,7 +164,74 @@ def test_collection_translation(user_api_client, published_collection, channel_U
)
+def test_collection_translation_without_description(
+ user_api_client, published_collection, channel_USD
+):
+ published_collection.translations.create(language_code="pl", name="Kolekcja")
+
+ query = """
+ query collectionById($collectionId: ID!, $channel: String) {
+ collection(id: $collectionId, channel: $channel) {
+ translation(languageCode: PL) {
+ name
+ description
+ descriptionJson
+ language {
+ code
+ }
+ }
+ }
+ }
+ """
+
+ collection_id = graphene.Node.to_global_id("Collection", published_collection.id)
+ variables = {"collectionId": collection_id, "channel": channel_USD.slug}
+ response = user_api_client.post_graphql(query, variables)
+ data = get_graphql_content(response)["data"]
+
+ translation_data = data["collection"]["translation"]
+ assert translation_data["name"] == "Kolekcja"
+ assert translation_data["language"]["code"] == "PL"
+ assert translation_data["description"] is None
+ assert translation_data["descriptionJson"] == "{}"
+
+
def test_category_translation(user_api_client, category):
+ description = dummy_editorjs("test description")
+ category.translations.create(
+ language_code="pl", name="Kategoria", description=description
+ )
+
+ query = """
+ query categoryById($categoryId: ID!) {
+ category(id: $categoryId) {
+ translation(languageCode: PL) {
+ name
+ description
+ descriptionJson
+ language {
+ code
+ }
+ }
+ }
+ }
+ """
+
+ category_id = graphene.Node.to_global_id("Category", category.id)
+ response = user_api_client.post_graphql(query, {"categoryId": category_id})
+ data = get_graphql_content(response)["data"]
+
+ translation_data = data["category"]["translation"]
+ assert translation_data["name"] == "Kategoria"
+ assert translation_data["language"]["code"] == "PL"
+ assert (
+ translation_data["description"]
+ == translation_data["descriptionJson"]
+ == dummy_editorjs("test description", json_format=True)
+ )
+
+
+def test_category_translation_without_description(user_api_client, category):
category.translations.create(language_code="pl", name="Kategoria")
query = """
@@ -141,6 +239,8 @@ def test_category_translation(user_api_client, category):
category(id: $categoryId) {
translation(languageCode: PL) {
name
+ description
+ descriptionJson
language {
code
}
@@ -153,8 +253,11 @@ def test_category_translation(user_api_client, category):
response = user_api_client.post_graphql(query, {"categoryId": category_id})
data = get_graphql_content(response)["data"]
- assert data["category"]["translation"]["name"] == "Kategoria"
- assert data["category"]["translation"]["language"]["code"] == "PL"
+ translation_data = data["category"]["translation"]
+ assert translation_data["name"] == "Kategoria"
+ assert translation_data["language"]["code"] == "PL"
+ assert translation_data["description"] is None
+ assert translation_data["descriptionJson"] == "{}"
def test_voucher_translation(staff_api_client, voucher, permission_manage_discounts):
@@ -242,6 +345,35 @@ def test_page_translation(user_api_client, page):
)
+def test_page_translation_without_content(user_api_client, page):
+ page.translations.create(language_code="pl", title="Strona")
+
+ query = """
+ query pageById($pageId: ID!) {
+ page(id: $pageId) {
+ translation(languageCode: PL) {
+ title
+ content
+ contentJson
+ language {
+ code
+ }
+ }
+ }
+ }
+ """
+
+ page_id = graphene.Node.to_global_id("Page", page.id)
+ response = user_api_client.post_graphql(query, {"pageId": page_id})
+ data = get_graphql_content(response)["data"]
+
+ translation_data = data["page"]["translation"]
+ assert translation_data["title"] == "Strona"
+ assert translation_data["language"]["code"] == "PL"
+ assert translation_data["content"] is None
+ assert translation_data["contentJson"] == "{}"
+
+
def test_attribute_translation(user_api_client, color_attribute):
color_attribute.translations.create(language_code="pl", name="Kolor")
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index 44afb864f4..2deb61ad78 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -143,7 +143,8 @@ class ProductTranslation(BaseTranslationType):
@staticmethod
def resolve_description_json(root: product_models.ProductTranslation, _info):
- return root.description
+ description = root.description
+ return description if description is not None else {}
class ProductTranslatableContent(CountableDjangoObjectType):
@@ -170,7 +171,8 @@ class ProductTranslatableContent(CountableDjangoObjectType):
@staticmethod
def resolve_description_json(root: product_models.Product, _info):
- return root.description
+ description = root.description
+ return description if description is not None else {}
class CollectionTranslation(BaseTranslationType):
@@ -188,7 +190,8 @@ class CollectionTranslation(BaseTranslationType):
@staticmethod
def resolve_description_json(root: product_models.CollectionTranslation, _info):
- return root.description
+ description = root.description
+ return description if description is not None else {}
class CollectionTranslatableContent(CountableDjangoObjectType):
@@ -218,7 +221,8 @@ class CollectionTranslatableContent(CountableDjangoObjectType):
@staticmethod
def resolve_description_json(root: product_models.Collection, _info):
- return root.description
+ description = root.description
+ return description if description is not None else {}
class CategoryTranslation(BaseTranslationType):
@@ -236,7 +240,8 @@ class CategoryTranslation(BaseTranslationType):
@staticmethod
def resolve_description_json(root: product_models.CategoryTranslation, _info):
- return root.description
+ description = root.description
+ return description if description is not None else {}
class CategoryTranslatableContent(CountableDjangoObjectType):
@@ -263,7 +268,8 @@ class CategoryTranslatableContent(CountableDjangoObjectType):
@staticmethod
def resolve_description_json(root: product_models.Category, _info):
- return root.description
+ description = root.description
+ return description if description is not None else {}
class PageTranslation(BaseTranslationType):
@@ -287,7 +293,8 @@ class PageTranslation(BaseTranslationType):
@staticmethod
def resolve_content_json(root: page_models.PageTranslation, _info):
- return root.content
+ content = root.content
+ return content if content is not None else {}
class PageTranslatableContent(CountableDjangoObjectType):
@@ -326,8 +333,9 @@ class PageTranslatableContent(CountableDjangoObjectType):
)
@staticmethod
- def resolve_description_json(root: page_models.Page, _info):
- return root.content
+ def resolve_content_json(root: page_models.Page, _info):
+ content = root.content
+ return content if content is not None else {}
class VoucherTranslation(BaseTranslationType):
diff --git a/saleor/page/migrations/0020_update_content_fields.py b/saleor/page/migrations/0020_update_content_fields.py
new file mode 100644
index 0000000000..56db057819
--- /dev/null
+++ b/saleor/page/migrations/0020_update_content_fields.py
@@ -0,0 +1,46 @@
+# Generated by Django 3.1.5 on 2021-02-08 11:02
+
+from django.db import migrations
+
+import saleor.core.db.fields
+import saleor.core.utils.editorjs
+
+
+def update_empty_content_field(apps, schema_editor):
+ Page = apps.get_model("page", "Page")
+ PageTranslation = apps.get_model("page", "PageTranslation")
+
+ Page.objects.filter(content={}).update(content=None)
+ PageTranslation.objects.filter(content={}).update(content=None)
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("page", "0019_auto_20210125_0905"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="page",
+ name="content",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="pagetranslation",
+ name="content",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.RunPython(
+ update_empty_content_field,
+ migrations.RunPython.noop,
+ ),
+ ]
diff --git a/saleor/page/models.py b/saleor/page/models.py
index 7b38b46c1e..20126fa92a 100644
--- a/saleor/page/models.py
+++ b/saleor/page/models.py
@@ -14,7 +14,7 @@ class Page(ModelWithMetadata, SeoModel, PublishableModel):
page_type = models.ForeignKey(
"PageType", related_name="pages", on_delete=models.CASCADE
)
- content = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)
+ content = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
created = models.DateTimeField(auto_now_add=True)
translated = TranslationProxy()
@@ -33,7 +33,7 @@ class PageTranslation(SeoModelTranslation):
Page, related_name="translations", on_delete=models.CASCADE
)
title = models.CharField(max_length=255, blank=True)
- content = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)
+ content = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
class Meta:
ordering = ("language_code", "page", "pk")
diff --git a/saleor/product/migrations/0141_update_descritpion_fields.py b/saleor/product/migrations/0141_update_descritpion_fields.py
new file mode 100644
index 0000000000..f429e1e71e
--- /dev/null
+++ b/saleor/product/migrations/0141_update_descritpion_fields.py
@@ -0,0 +1,95 @@
+# Generated by Django 3.1.5 on 2021-02-17 11:04
+
+from django.db import migrations
+
+import saleor.core.db.fields
+import saleor.core.utils.editorjs
+
+
+def update_empty_description_field(apps, schema_editor):
+ Category = apps.get_model("product", "Category")
+ CategoryTranslation = apps.get_model("product", "CategoryTranslation")
+ Collection = apps.get_model("product", "Collection")
+ CollectionTranslation = apps.get_model("product", "CollectionTranslation")
+ Product = apps.get_model("product", "Product")
+ ProductTranslation = apps.get_model("product", "ProductTranslation")
+
+ models = [
+ Category,
+ CategoryTranslation,
+ Collection,
+ CollectionTranslation,
+ Product,
+ ProductTranslation,
+ ]
+
+ for model in models:
+ model.objects.filter(description={}).update(description=None)
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("product", "0140_auto_20210125_0905"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="category",
+ name="description",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="categorytranslation",
+ name="description",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="collection",
+ name="description",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="collectiontranslation",
+ name="description",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="product",
+ name="description",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="producttranslation",
+ name="description",
+ field=saleor.core.db.fields.SanitizedJSONField(
+ blank=True,
+ null=True,
+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,
+ ),
+ ),
+ migrations.RunPython(
+ update_empty_description_field,
+ migrations.RunPython.noop,
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index bd1d0a7c57..2d632e4f11 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -59,9 +59,7 @@ if TYPE_CHECKING:
class Category(MPTTModel, ModelWithMetadata, SeoModel):
name = models.CharField(max_length=250)
slug = models.SlugField(max_length=255, unique=True, allow_unicode=True)
- description = SanitizedJSONField(
- blank=True, default=dict, sanitizer=clean_editor_js
- )
+ description = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
parent = models.ForeignKey(
"self", null=True, blank=True, related_name="children", on_delete=models.CASCADE
)
@@ -84,9 +82,7 @@ class CategoryTranslation(SeoModelTranslation):
Category, related_name="translations", on_delete=models.CASCADE
)
name = models.CharField(max_length=128)
- description = SanitizedJSONField(
- blank=True, default=dict, sanitizer=clean_editor_js
- )
+ description = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
class Meta:
unique_together = (("language_code", "category"),)
@@ -308,9 +304,7 @@ class Product(SeoModel, ModelWithMetadata):
)
name = models.CharField(max_length=250)
slug = models.SlugField(max_length=255, unique=True, allow_unicode=True)
- description = SanitizedJSONField(
- blank=True, default=dict, sanitizer=clean_editor_js
- )
+ description = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
description_plaintext = TextField(blank=True)
search_vector = SearchVectorField(null=True, blank=True)
@@ -382,9 +376,7 @@ class ProductTranslation(SeoModelTranslation):
Product, related_name="translations", on_delete=models.CASCADE
)
name = models.CharField(max_length=250)
- description = SanitizedJSONField(
- blank=True, default=dict, sanitizer=clean_editor_js
- )
+ description = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
class Meta:
unique_together = (("language_code", "product"),)
@@ -700,9 +692,7 @@ class Collection(SeoModel, ModelWithMetadata):
upload_to="collection-backgrounds", blank=True, null=True
)
background_image_alt = models.CharField(max_length=128, blank=True)
- description = SanitizedJSONField(
- blank=True, default=dict, sanitizer=clean_editor_js
- )
+ description = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
objects = CollectionsQueryset.as_manager()
@@ -742,9 +732,7 @@ class CollectionTranslation(SeoModelTranslation):
Collection, related_name="translations", on_delete=models.CASCADE
)
name = models.CharField(max_length=128)
- description = SanitizedJSONField(
- blank=True, default=dict, sanitizer=clean_editor_js
- )
+ description = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
class Meta:
unique_together = (("language_code", "collection"),)