Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change type of description field from String to JSONString (#6692)
Damian Wysockid37b45ac0b16
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 398b09fd59..ed08fca4ca 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -34,6 +34,7 @@ All notable, unreleased changes to this project will be documented in this file.- Get tax rate from plugins - #6649 by @IKarbowiak- Added support for querying user by email - #6632 @LeOndaz- Add order shipping tax rate - #6678 by @IKarbowiak+- Deprecate field `descriptionJSON` from `Product`, `Category`, `Collection` and field `contentJSON` from `Page` - #6692 by @d-wysocki- Fix products visibility - #6704 by @IKarbowiak- Introduce page reference attributes - #6624 by @IKarbowiak- Introduce product reference attributes - #6711 by @IKarbowiakdiff --git a/saleor/core/sanitizers/__init__.py b/saleor/core/sanitizers/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/core/tests/test_editorjs_sanitizer.py b/saleor/core/tests/test_editorjs.pysimilarity index 84%rename from saleor/core/tests/test_editorjs_sanitizer.pyrename to saleor/core/tests/test_editorjs.pyindex fad1fef737..9e7f500804 100644--- a/saleor/core/tests/test_editorjs_sanitizer.py+++ b/saleor/core/tests/test_editorjs.py@@ -3,7 +3,7 @@ from unittest import mockimport pytest-from ..sanitizers.editorjs_sanitizer import clean_editor_js+from ..utils.editorjs import clean_editor_js@pytest.mark.parametrize(@@ -30,6 +30,12 @@ def test_clean_editor_js(text):# thenassert result == data+ # when+ result = clean_editor_js(data, to_string=True)++ # then+ assert result == text+def test_clean_editor_js_no_blocks():# given@@ -41,6 +47,12 @@ def test_clean_editor_js_no_blocks():# thenassert result == data+ # when+ result = clean_editor_js(data, to_string=True)++ # then+ assert result == ""+def test_clean_editor_js_no_data():# given@@ -52,8 +64,14 @@ def test_clean_editor_js_no_data():# thenassert result == data+ # when+ result = clean_editor_js(data, to_string=True)[email protected]("saleor.core.sanitizers.editorjs_sanitizer.parse_url")+ # then+ assert result == ""++[email protected]("saleor.core.utils.editorjs.parse_url")def test_clean_editor_js_invalid_url(parse_url_mock):# givenresponse_mock = mock.Mock()@@ -115,8 +133,21 @@ def test_clean_editor_js_for_list():# thenassert result == data+ # when+ result = clean_editor_js(data, to_string=True)++ # then+ assert result == (+ "The Saleor Winter Sale is snowed "+ '<a href="https://docs.saleor.io/docs/">. Test.'+ "It is a block-styled editor "+ '<a href="https://docs.saleor.io/docs/">.'+ "It returns clean data output in JSON"+ "Designed to be extendable and pluggable with a simple API"+ )+[email protected]("saleor.core.sanitizers.editorjs_sanitizer.parse_url")[email protected]("saleor.core.utils.editorjs.parse_url")def test_clean_editor_js_for_list_invalid_url(parse_url_mock):# givenresponse_mock = mock.Mock()diff --git a/saleor/core/tests/test_postgresql_search.py b/saleor/core/tests/test_postgresql_search.pyindex ede00a57f1..362fefe56e 100644--- a/saleor/core/tests/test_postgresql_search.py+++ b/saleor/core/tests/test_postgresql_search.py@@ -2,8 +2,9 @@ import pytestfrom django.utils.text import slugifyfrom ...account.models import Address+from ...graphql.product.filters import product_searchfrom ...product.models import Product, ProductChannelListing-from ...search.backends.postgresql import search_storefront+from ...tests.utils import dummy_editorjsPRODUCTS = [("Arabica Coffee", "The best grains in galactic"),@@ -18,7 +19,8 @@ def named_products(category, product_type, channel_USD):product = Product.objects.create(name=name,slug=slugify(name),- description=description,+ description=dummy_editorjs(description),+ description_plaintext=description,product_type=product_type,category=category,)@@ -34,7 +36,7 @@ def named_products(category, product_type, channel_USD):def execute_search(phrase):"""Execute storefront search."""- return search_storefront(phrase)+ return product_search(phrase)@pytest.mark.parametrize(diff --git a/saleor/core/sanitizers/editorjs_sanitizer.py b/saleor/core/utils/editorjs.pysimilarity index 75%rename from saleor/core/sanitizers/editorjs_sanitizer.pyrename to saleor/core/utils/editorjs.pyindex a8deb0a8f9..75166d92b0 100644--- a/saleor/core/sanitizers/editorjs_sanitizer.py+++ b/saleor/core/utils/editorjs.py@@ -7,15 +7,19 @@ BLACKLISTED_URL_SCHEMES = ("javascript",)HYPERLINK_TAG_WITH_URL_PATTERN = r"(.*?<a\s+href=\\?\")(\w+://\S+[^\\])(\\?\">)"-def clean_editor_js(definitions: dict):+def clean_editor_js(definitions: 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.++ `to_string` flag is used for returning concatenated string from all blocks+ instead of returning json object."""+ string = ""blocks = definitions.get("blocks")if not blocks or not isinstance(blocks, list):- return definitions+ return string if to_string else definitionsfor index, block in enumerate(blocks):block_type = block["type"]@@ -28,16 +32,21 @@ def clean_editor_js(definitions: dict):if not item:continuenew_text = clean_text_data(item)- blocks[index]["data"]["items"][item_index] = new_text+ if to_string:+ string += new_text+ else:+ blocks[index]["data"]["items"][item_index] = new_textelse:text = block["data"]["text"]if not text:continuenew_text = clean_text_data(text)+ if to_string:+ string += new_text+ else:+ blocks[index]["data"]["text"] = new_text- blocks[index]["data"]["text"] = new_text-- return definitions+ return string if to_string else definitionsdef clean_text_data(text: str):diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex b126d27129..3a3d112e0e 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -1319,19 +1319,7 @@ def create_pages():"title": "About","slug": "about","page_type_id": 1,- "content": """- <h2>E-commerce for the PWA era</h2>- <h3>A modular, high performance e-commerce storefront built- with GraphQL, Django, and ReactJS.</h3>- <p>Saleor is a rapidly-growing open source e-commerce platform that- has served high-volume companies from branches like publishing- and apparel since 2012. Based on Python and Django, the latest major- update introduces a modular front end with a GraphQL API and storefront- and dashboard written in React to make Saleor a full-functionality- open source e-commerce.</p>- <p><a href="https://github.com/mirumee/saleor">Get Saleor today!</a></p>- """,- "content_json": {+ "content": {"blocks": [{"data": {"text": "E-commerce for the PWA era", "level": 2},@@ -1380,11 +1368,7 @@ def create_pages():"title": "Apple juice details","slug": "apple-juice-details","page_type_id": 3,- "content": (- "\n<h2>Apple juice details</h2>\n"- "<p>This is example product details page.</p>\n"- ),- "content_json": {+ "content": {"blocks": [{"data": {"text": "Apple juice details", "level": 2},@@ -1403,7 +1387,6 @@ def create_pages():data = data_pages[pk]page_data = {"content": data["content"],- "content_json": data["content_json"],"title": data["title"],"is_published": True,"page_type_id": data["page_type_id"],diff --git a/saleor/discount/tests/test_discounts.py b/saleor/discount/tests/test_discounts.pyindex 025ce89b24..75bb6db5a4 100644--- a/saleor/discount/tests/test_discounts.py+++ b/saleor/discount/tests/test_discounts.py@@ -241,7 +241,7 @@ def test_sale_applies_to_correct_products(product_type, category, channel_USD):product = Product.objects.create(name="Test Product",slug="test-product",- description="",+ description={},pk=111,product_type=product_type,category=category,@@ -256,7 +256,7 @@ def test_sale_applies_to_correct_products(product_type, category, channel_USD):product2 = Product.objects.create(name="Second product",slug="second-product",- description="",+ description={},product_type=product_type,category=category,)diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_query.py b/saleor/graphql/attribute/tests/queries/test_attribute_query.pyindex 18d6d10e07..05dadbabb6 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_query.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_query.py@@ -5,6 +5,7 @@ from graphene.utils.str_converters import to_camel_casefrom .....attribute.models import Attributefrom .....product.models import Category, Collection, Product, ProductType+from .....tests.utils import dummy_editorjsfrom ....tests.utils import assert_no_permission, get_graphql_content@@ -471,7 +472,7 @@ def test_attributes_in_collection_query(other_collection = Collection.objects.create(name="Other Collection",slug="other-collection",- description="Description",+ description=dummy_editorjs("Test description"),)other_collection.products.add(other_product)diff --git a/saleor/graphql/page/mutations/pages.py b/saleor/graphql/page/mutations/pages.pyindex 9d3957d436..ca8d31bf1b 100644--- a/saleor/graphql/page/mutations/pages.py+++ b/saleor/graphql/page/mutations/pages.py@@ -27,10 +27,7 @@ if TYPE_CHECKING:class PageInput(graphene.InputObjectType):slug = graphene.String(description="Page internal name.")title = graphene.String(description="Page title.")- content = graphene.String(- description=("Page content. May consist of ordinary text, HTML and images.")- )- content_json = graphene.JSONString(description="Page content in JSON format.")+ content = graphene.JSONString(description="Page content in JSON format.")attributes = graphene.List(graphene.NonNull(AttributeValueInput), description="List of attributes.")diff --git a/saleor/graphql/page/tests/test_page.py b/saleor/graphql/page/tests/test_page.pyindex da934116c3..bcc87d51eb 100644--- a/saleor/graphql/page/tests/test_page.py+++ b/saleor/graphql/page/tests/test_page.py@@ -1,5 +1,3 @@-import json-import grapheneimport pytestfrom django.utils import timezone@@ -10,6 +8,7 @@ from ....attribute.models import AttributeValuefrom ....attribute.utils import associate_attribute_values_to_instancefrom ....page.error_codes import PageErrorCodefrom ....page.models import Page, PageType+from ....tests.utils import dummy_editorjsfrom ...tests.utils import get_graphql_contentPAGE_QUERY = """@@ -170,19 +169,18 @@ def test_get_page_with_sorted_attribute_values(CREATE_PAGE_MUTATION = """mutation CreatePage(- $slug: String, $title: String, $content: String, $pageType: ID!- $contentJson: JSONString, $isPublished: Boolean,+ $slug: String, $title: String, $content: JSONString, $pageType: ID!+ $isPublished: Boolean,$attributes: [AttributeValueInput!]) {pageCreate(input: {slug: $slug, title: $title, pageType: $pageType- content: $content, contentJson: $contentJson+ content: $contentisPublished: $isPublished, attributes: $attributes}) {page {idtitlecontent- contentJsonslugisPublishedpublicationDate@@ -218,8 +216,7 @@ CREATE_PAGE_MUTATION = """@freeze_time("2020-03-18 12:00:00")def test_page_create_mutation(staff_api_client, permission_manage_pages, page_type):page_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type_id = graphene.Node.to_global_id("PageType", page_type.pk)@@ -238,7 +235,6 @@ def test_page_create_mutation(staff_api_client, permission_manage_pages, page_tyvariables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -256,7 +252,6 @@ def test_page_create_mutation(staff_api_client, permission_manage_pages, page_tyassert data["pageErrors"] == []assert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["publicationDate"] == "2020-03-18"@@ -306,8 +301,7 @@ def test_page_create_mutation_missing_required_attributes():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type_id = graphene.Node.to_global_id("PageType", page_type.pk)@@ -326,7 +320,6 @@ def test_page_create_mutation_missing_required_attributes(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -357,8 +350,7 @@ def test_page_create_mutation_empty_attribute_value():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type_id = graphene.Node.to_global_id("PageType", page_type.pk)@@ -371,7 +363,6 @@ def test_page_create_mutation_empty_attribute_value(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -402,8 +393,7 @@ def test_create_page_with_file_attribute():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -421,7 +411,6 @@ def test_create_page_with_file_attribute(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -441,7 +430,6 @@ def test_create_page_with_file_attribute(assert not errorsassert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["pageType"]["id"] == page_type_id@@ -468,8 +456,7 @@ def test_create_page_with_file_attribute_new_attribute_value():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -488,7 +475,6 @@ def test_create_page_with_file_attribute_new_attribute_value(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -514,7 +500,6 @@ def test_create_page_with_file_attribute_new_attribute_value(assert not errorsassert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["pageType"]["id"] == page_type_id@@ -544,8 +529,7 @@ def test_create_page_with_file_attribute_not_required_no_file_url_given():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -563,7 +547,6 @@ def test_create_page_with_file_attribute_not_required_no_file_url_given(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -580,7 +563,6 @@ def test_create_page_with_file_attribute_not_required_no_file_url_given(assert data["pageErrors"] == []assert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["pageType"]["id"] == page_type_id@@ -593,8 +575,7 @@ def test_create_page_with_file_attribute_required_no_file_url_given():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -612,7 +593,6 @@ def test_create_page_with_file_attribute_required_no_file_url_given(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -643,8 +623,7 @@ def test_create_page_with_page_reference_attribute():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -664,7 +643,6 @@ def test_create_page_with_page_reference_attribute(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -684,7 +662,6 @@ def test_create_page_with_page_reference_attribute(assert not errorsassert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["pageType"]["id"] == page_type_id@@ -716,8 +693,7 @@ def test_create_page_with_page_reference_attribute_not_required_no_references_gi):# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -737,7 +713,6 @@ def test_create_page_with_page_reference_attribute_not_required_no_references_givariables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -754,7 +729,6 @@ def test_create_page_with_page_reference_attribute_not_required_no_references_giassert data["pageErrors"] == []assert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["pageType"]["id"] == page_type_id@@ -770,8 +744,7 @@ def test_create_page_with_page_reference_attribute_required_no_references_given():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -791,7 +764,6 @@ def test_create_page_with_page_reference_attribute_required_no_references_given(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -822,8 +794,7 @@ def test_create_page_with_product_reference_attribute():# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -843,7 +814,6 @@ def test_create_page_with_product_reference_attribute(variables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -863,7 +833,6 @@ def test_create_page_with_product_reference_attribute(assert not errorsassert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["pageType"]["id"] == page_type_id@@ -895,8 +864,7 @@ def test_create_page_with_product_reference_attribute_not_required_no_references):# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -916,7 +884,6 @@ def test_create_page_with_product_reference_attribute_not_required_no_referencesvariables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -933,7 +900,6 @@ def test_create_page_with_product_reference_attribute_not_required_no_referencesassert data["pageErrors"] == []assert data["page"]["title"] == page_titleassert data["page"]["content"] == page_content- assert data["page"]["contentJson"] == page_content_jsonassert data["page"]["slug"] == page_slugassert data["page"]["isPublished"] == page_is_publishedassert data["page"]["pageType"]["id"] == page_type_id@@ -949,8 +915,7 @@ def test_create_page_with_product_reference_attribute_required_no_references_giv):# givenpage_slug = "test-slug"- page_content = "test content"- page_content_json = json.dumps({"content": "test content"})+ page_content = dummy_editorjs("test content", True)page_title = "test title"page_is_published = Truepage_type = PageType.objects.create(@@ -970,7 +935,6 @@ def test_create_page_with_product_reference_attribute_required_no_references_givvariables = {"title": page_title,"content": page_content,- "contentJson": page_content_json,"isPublished": page_is_published,"slug": page_slug,"pageType": page_type_id,@@ -1469,7 +1433,7 @@ def test_public_page_sets_publication_date(data = {"slug": "test-url","title": "Test page",- "content": "test content",+ "content": dummy_editorjs("Content for page 1"),"is_published": False,"page_type": page_type,}@@ -1665,14 +1629,14 @@ def test_paginate_pages(user_api_client, page, page_type):data_02 = {"slug": "test02-url","title": "Test page",- "content": "test content",+ "content": dummy_editorjs("Content for page 1"),"is_published": True,"page_type": page_type,}data_03 = {"slug": "test03-url","title": "Test page",- "content": "test content",+ "content": dummy_editorjs("Content for page 1"),"is_published": True,"page_type": page_type,}@@ -1768,19 +1732,19 @@ def test_pages_query_with_filter(Page.objects.create(title="Page1",slug="slug_page_1",- content="Content for page 1",+ content=dummy_editorjs("Content for page 1"),page_type=page_type,)Page.objects.create(title="Page2",slug="slug_page_2",- content="Content for page 2",+ content=dummy_editorjs("Content for page 2"),page_type=page_type,)Page.objects.create(title="About",slug="slug_about",- content="About test content",+ content=dummy_editorjs("About test content"),page_type=page_type,)variables = {"filter": page_filter}@@ -1831,7 +1795,7 @@ def test_query_pages_with_sort(Page.objects.create(title="Page1",slug="slug_page_1",- content="p1",+ content=dummy_editorjs("p1."),is_published=True,publication_date=timezone.now().replace(year=2018, month=12, day=5),page_type=page_type,@@ -1840,7 +1804,7 @@ def test_query_pages_with_sort(Page.objects.create(title="Page2",slug="page_2",- content="p2",+ content=dummy_editorjs("p2."),is_published=False,publication_date=timezone.now().replace(year=2019, month=12, day=5),page_type=page_type,@@ -1849,7 +1813,7 @@ def test_query_pages_with_sort(Page.objects.create(title="About",slug="about",- content="Ab",+ content=dummy_editorjs("Ab."),is_published=True,page_type=page_type,)diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.pyindex 872215d592..17e69bb49d 100644--- a/saleor/graphql/page/types.py+++ b/saleor/graphql/page/types.py@@ -21,6 +21,13 @@ from .dataloaders import (class Page(CountableDjangoObjectType):+ content_json = graphene.String(+ description="Content of the page (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `content` field instead."+ ),+ required=True,+ )translation = TranslationField(PageTranslation, type_name="page")attributes = graphene.List(graphene.NonNull(SelectedAttribute),@@ -35,7 +42,6 @@ class Page(CountableDjangoObjectType):)only_fields = ["content",- "content_json","created","id","is_published",diff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.pyindex dfbe3d6183..3a1291c26e 100644--- a/saleor/graphql/product/filters.py+++ b/saleor/graphql/product/filters.py@@ -3,6 +3,7 @@ from typing import Dict, Iterable, List, Optionalimport django_filtersimport graphene+from django.contrib.postgres.search import TrigramSimilarityfrom django.db.models import Exists, F, OuterRef, Q, Subquery, Sumfrom django.db.models.functions import Coalescefrom graphene_django.filter import GlobalIDFilter, GlobalIDMultipleChoiceFilter@@ -13,7 +14,6 @@ from ...attribute.models import (Attribute,)from ...product.models import Category, Collection, Product, ProductType, ProductVariant-from ...search.backends import pickerfrom ...warehouse.models import Stockfrom ..channel.filters import get_channel_slug_from_filter_datafrom ..core.filters import EnumFilter, ListObjectTypeFilter, ObjectTypeFilter@@ -209,10 +209,29 @@ def filter_stock_availability(qs, _, value):return qs+def product_search(phrase):+ """Return matching products for storefront views.++ Fuzzy storefront search that is resistant to small typing errors made+ by user. Name is matched using trigram similarity, description uses+ standard postgres full text search.++ Args:+ phrase (str): searched phrase++ """+ name_sim = TrigramSimilarity("name", phrase)+ ft_in_description = Q(search_vector=phrase)+ ft_by_sku = Q(variants__sku__search=phrase)+ name_similar = Q(name_sim__gt=0.2)+ return Product.objects.annotate(name_sim=name_sim).filter(+ (ft_in_description | name_similar | ft_by_sku)+ )++def filter_search(qs, _, value):if value:- search = picker.pick_backend()- qs = qs.distinct() & search(value).distinct()+ qs = qs.distinct() & product_search(value).distinct()return qsdiff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex c13795129b..1b15d4b7b9 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -12,6 +12,7 @@ from ....attribute import AttributeInputType, AttributeTypefrom ....attribute import models as attribute_modelsfrom ....core.exceptions import PermissionDeniedfrom ....core.permissions import ProductPermissions, ProductTypePermissions+from ....core.utils.editorjs import clean_editor_jsfrom ....order import OrderStatusfrom ....order import models as order_modelsfrom ....product import models@@ -60,8 +61,7 @@ from ..utils import (class CategoryInput(graphene.InputObjectType):- description = graphene.String(description="Category description (HTML/text).")- description_json = graphene.JSONString(description="Category description (JSON).")+ description = graphene.JSONString(description="Category description (JSON).")name = graphene.String(description="Category name.")slug = graphene.String(description="Category slug.")seo = SeoInput(description="Search engine optimization fields.")@@ -171,10 +171,7 @@ class CollectionInput(graphene.InputObjectType):)name = graphene.String(description="Name of the collection.")slug = graphene.String(description="Slug of the collection.")- description = graphene.String(- description="Description of the collection (HTML/text)."- )- description_json = graphene.JSONString(+ description = graphene.JSONString(description="Description of the collection (JSON).")background_image = Upload(description="Background image file.")@@ -484,8 +481,7 @@ class ProductInput(graphene.InputObjectType):description="List of IDs of collections that the product belongs to.",name="collections",)- description = graphene.String(description="Product description (HTML/text).")- description_json = graphene.JSONString(description="Product description (JSON).")+ description = graphene.JSONString(description="Product description (JSON).")name = graphene.String(description="Product name.")slug = graphene.String(description="Product slug.")tax_code = graphene.String(description="Tax rate for enabled tax gateway.")@@ -539,6 +535,11 @@ class ProductCreate(ModelMutation):def clean_input(cls, info, instance, data):cleaned_input = super().clean_input(info, instance, data)+ description = cleaned_input.get("description")+ cleaned_input["description_plaintext"] = (+ clean_editor_js(description, to_string=True) if description else ""+ )+weight = cleaned_input.get("weight")if weight and weight.value < 0:raise ValidationError(@@ -611,7 +612,6 @@ class ProductCreate(ModelMutation):@transaction.atomicdef save(cls, info, instance, cleaned_input):instance.save()-attributes = cleaned_input.get("attributes")if attributes:AttributeAssignmentMixin.save(instance, attributes)diff --git a/saleor/graphql/product/tests/deprecated/test_collection.py b/saleor/graphql/product/tests/deprecated/test_collection.pyindex d15f072a17..d9a68501a9 100644--- a/saleor/graphql/product/tests/deprecated/test_collection.py+++ b/saleor/graphql/product/tests/deprecated/test_collection.py@@ -1,3 +1,4 @@+import jsonimport warningsfrom .....channel.utils import DEPRECATION_WARNING_MESSAGE@@ -37,7 +38,9 @@ def test_collections_query_with_default_channel_slug(collection_data = edges[0]["node"]assert collection_data["name"] == published_collection.nameassert collection_data["slug"] == published_collection.slug- assert collection_data["description"] == published_collection.description+ assert collection_data["description"] == json.dumps(+ published_collection.description+ )assert (collection_data["products"]["totalCount"]== published_collection.products.count()diff --git a/saleor/graphql/product/tests/test_category.py b/saleor/graphql/product/tests/test_category.pyindex 671e6a2a23..dac09b4eaf 100644--- a/saleor/graphql/product/tests/test_category.py+++ b/saleor/graphql/product/tests/test_category.py@@ -1,4 +1,3 @@-import jsonfrom unittest.mock import Mock, patchimport graphene@@ -9,6 +8,7 @@ from graphql_relay import to_global_idfrom ....product.error_codes import ProductErrorCodefrom ....product.models import Category, Product, ProductChannelListingfrom ....product.tests.utils import create_image, create_pdf_file_with_image_ext+from ....tests.utils import dummy_editorjsfrom ...tests.utils import get_graphql_content, get_multipart_request_bodyQUERY_CATEGORY = """@@ -217,15 +217,14 @@ def test_query_category_product_only_visible_in_listings_as_app_with_perm(CATEGORY_CREATE_MUTATION = """mutation(- $name: String, $slug: String, $description: String,- $descriptionJson: JSONString, $backgroundImage: Upload,+ $name: String, $slug: String,+ $description: JSONString, $backgroundImage: Upload,$backgroundImageAlt: String, $parentId: ID) {categoryCreate(input: {name: $nameslug: $slugdescription: $description- descriptionJson: $descriptionJsonbackgroundImage: $backgroundImagebackgroundImageAlt: $backgroundImageAlt},@@ -236,7 +235,6 @@ CATEGORY_CREATE_MUTATION = """nameslugdescription- descriptionJsonparent {nameid@@ -271,8 +269,7 @@ def test_category_create_mutation(category_name = "Test category"category_slug = slugify(category_name)- category_description = "Test description"- category_description_json = json.dumps({"content": "description"})+ category_description = dummy_editorjs("description", True)image_file, image_name = create_image()image_alt = "Alt text for an image."@@ -280,7 +277,6 @@ def test_category_create_mutation(variables = {"name": category_name,"description": category_description,- "descriptionJson": category_description_json,"backgroundImage": image_name,"backgroundImageAlt": image_alt,"slug": category_slug,@@ -294,7 +290,6 @@ def test_category_create_mutation(assert data["productErrors"] == []assert data["category"]["name"] == category_nameassert data["category"]["description"] == category_description- assert data["category"]["descriptionJson"] == category_description_jsonassert not data["category"]["parent"]category = Category.objects.get(name=category_name)assert category.background_image.file@@ -360,6 +355,7 @@ def test_category_create_mutation_without_background_image(monkeypatch, staff_api_client, permission_manage_products):query = CATEGORY_CREATE_MUTATION+ description = dummy_editorjs("description", True)mock_create_thumbnails = Mock(return_value=None)monkeypatch.setattr(@@ -374,7 +370,7 @@ def test_category_create_mutation_without_background_image(category_name = "Test category"variables = {"name": category_name,- "description": "Test description",+ "description": description,"slug": slugify(category_name),}response = staff_api_client.post_graphql(@@ -389,7 +385,7 @@ def test_category_create_mutation_without_background_image(MUTATION_CATEGORY_UPDATE_MUTATION = """mutation($id: ID!, $name: String, $slug: String,$backgroundImage: Upload, $backgroundImageAlt: String,- $description: String) {+ $description: JSONString) {categoryUpdate(id: $id@@ -439,7 +435,8 @@ def test_category_update_mutation(category_name = "Updated name"category_slug = slugify(category_name)- category_description = "Updated description"+ category_description = dummy_editorjs("description", True)+image_file, image_name = create_image()image_alt = "Alt text for an image."@@ -502,7 +499,7 @@ def test_category_update_mutation_without_background_image(monkeypatch, staff_api_client, category, permission_manage_products):query = """- mutation($id: ID!, $name: String, $slug: String, $description: String) {+ mutation($id: ID!, $name: String, $slug: String, $description: JSONString) {categoryUpdate(id: $idinput: {@@ -534,7 +531,7 @@ def test_category_update_mutation_without_background_image("Category", category.children.create(name="child").pk),"name": category_name,- "description": "Updated description",+ "description": dummy_editorjs("description", True),"slug": slugify(category_name),}response = staff_api_client.post_graphql(diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.pyindex b9d46b39f8..c676e7e7b9 100644--- a/saleor/graphql/product/tests/test_collection.py+++ b/saleor/graphql/product/tests/test_collection.py@@ -8,6 +8,7 @@ from graphql_relay import to_global_idfrom ....product.error_codes import CollectionErrorCode, ProductErrorCodefrom ....product.models import Collection, Productfrom ....product.tests.utils import create_image, create_pdf_file_with_image_ext+from ....tests.utils import dummy_editorjsfrom ...tests.utils import get_graphql_content, get_multipart_request_bodyQUERY_COLLECTION = """@@ -171,7 +172,9 @@ def test_collections_query(collection_data = edges[0]["node"]assert collection_data["name"] == published_collection.nameassert collection_data["slug"] == published_collection.slug- assert collection_data["description"] == published_collection.description+ assert collection_data["description"] == json.dumps(+ published_collection.description+ )assert (collection_data["products"]["totalCount"]== published_collection.products.count()@@ -335,15 +338,14 @@ def test_filter_collection_products_by_multiple_attributes(CREATE_COLLECTION_MUTATION = """mutation createCollection(- $name: String!, $slug: String, $description: String,- $descriptionJson: JSONString, $products: [ID],+ $name: String!, $slug: String,+ $description: JSONString, $products: [ID],$backgroundImage: Upload, $backgroundImageAlt: String) {collectionCreate(input: {name: $name,slug: $slug,description: $description,- descriptionJson: $descriptionJson,products: $products,backgroundImage: $backgroundImage,backgroundImageAlt: $backgroundImageAlt}) {@@ -351,7 +353,6 @@ CREATE_COLLECTION_MUTATION = """nameslugdescription- descriptionJsonproducts {totalCount}@@ -388,13 +389,11 @@ def test_create_collection(image_alt = "Alt text for an image."name = "test-name"slug = "test-slug"- description = "test-description"- description_json = json.dumps({"content": "description"})+ description = dummy_editorjs("description", True)variables = {"name": name,"slug": slug,"description": description,- "descriptionJson": description_json,"products": product_ids,"backgroundImage": image_name,"backgroundImageAlt": image_alt,@@ -408,7 +407,6 @@ def test_create_collection(assert data["name"] == nameassert data["slug"] == slugassert data["description"] == description- assert data["descriptionJson"] == description_jsonassert data["products"]["totalCount"] == len(product_ids)collection = Collection.objects.get(slug=slug)assert collection.background_image.file@@ -483,7 +481,7 @@ def test_update_collection():query = """mutation updateCollection(- $name: String!, $slug: String!, $description: String, $id: ID!) {+ $name: String!, $slug: String!, $description: JSONString, $id: ID!) {collectionUpdate(id: $id, input: {name: $name, slug: $slug, description: $description}) {@@ -496,7 +494,7 @@ def test_update_collection(}}"""-+ description = dummy_editorjs("test description", True)mock_create_thumbnails = Mock(return_value=None)monkeypatch.setattr((@@ -508,7 +506,7 @@ def test_update_collection(name = "new-name"slug = "new-slug"- description = "new-description"+ description = descriptionvariables = {"name": name,"slug": slug,diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex d0eeeaf687..585227c00c 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -36,6 +36,7 @@ from ....product.models import (from ....product.tasks import update_variants_namesfrom ....product.tests.utils import create_image, create_pdf_file_with_image_extfrom ....product.utils.costs import get_product_costs_data+from ....tests.utils import dummy_editorjsfrom ....warehouse.models import Allocation, Stock, Warehousefrom ...core.enums import AttributeErrorCode, ReportingPeriodfrom ...tests.utils import (@@ -2191,7 +2192,7 @@ CREATE_PRODUCT_MUTATION = """category {name}- descriptionJson+ descriptionchargeTaxestaxType {taxCode@@ -2273,7 +2274,7 @@ def test_create_product("category": category_id,"name": product_name,"slug": product_slug,- "descriptionJson": description_json,+ "description": description_json,"chargeTaxes": product_charge_taxes,"taxCode": product_tax_rate,"attributes": [@@ -2291,7 +2292,7 @@ def test_create_product(assert data["productErrors"] == []assert data["product"]["name"] == product_nameassert data["product"]["slug"] == product_slug- assert data["product"]["descriptionJson"] == description_json+ assert data["product"]["description"] == description_jsonassert data["product"]["chargeTaxes"] == product_charge_taxesassert data["product"]["taxType"]["taxCode"] == product_tax_rateassert data["product"]["productType"]["name"] == product_type.name@@ -2304,6 +2305,80 @@ def test_create_product(assert color_value_slug in values+def test_create_product_description_plaintext(+ staff_api_client,+ product_type,+ category,+ size_attribute,+ permission_manage_products,+ monkeypatch,+):+ query = CREATE_PRODUCT_MUTATION+ description = "some test description"+ description_json = dummy_editorjs(description, json_format=True)++ product_type_id = graphene.Node.to_global_id("ProductType", product_type.pk)+ category_id = graphene.Node.to_global_id("Category", category.pk)+ product_name = "test name"+ product_slug = "product-test-slug"+ product_charge_taxes = True+ product_tax_rate = "STANDARD"++ # Mock tax interface with fake response from tax gateway+ monkeypatch.setattr(+ PluginsManager,+ "get_tax_code_from_object_meta",+ lambda self, x: TaxType(description="", code=product_tax_rate),+ )++ variables = {+ "input": {+ "productType": product_type_id,+ "category": category_id,+ "name": product_name,+ "slug": product_slug,+ "description": description_json,+ "chargeTaxes": product_charge_taxes,+ "taxCode": product_tax_rate,+ }+ }++ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)+ data = content["data"]["productCreate"]+ assert not data["productErrors"]++ product = Product.objects.all().first()+ product.description_plaintext = description+++def test_search_product_by_description(user_api_client, product_list, channel_USD):+ search_query = """+ query Products($filters: ProductFilterInput, $channel: String) {+ products(first: 5, filter: $filters, channel: $channel) {+ edges {+ node {+ id+ name+ }+ }+ }+ }+ """+ variables = {"filters": {"search": "big"}, "channel": channel_USD.slug}+ response = user_api_client.post_graphql(search_query, variables)+ content = get_graphql_content(response)+ assert len(content["data"]["products"]["edges"]) == 2++ variables = {"filters": {"search": "small"}, "channel": channel_USD.slug}+ response = user_api_client.post_graphql(search_query, variables)+ content = get_graphql_content(response)++ assert len(content["data"]["products"]["edges"]) == 1++@freeze_time("2020-03-18 12:00:00")def test_create_product_with_rating(staff_api_client,@@ -3319,7 +3394,7 @@ def test_create_product_invalid_product_attributes("category": category_id,"name": product_name,"slug": product_slug,- "descriptionJson": description_json,+ "description": description_json,"chargeTaxes": product_charge_taxes,"taxCode": product_tax_rate,"attributes": [@@ -3522,7 +3597,7 @@ MUTATION_UPDATE_PRODUCT = """name}rating- descriptionJson+ descriptionchargeTaxesvariants {name@@ -3600,7 +3675,7 @@ def test_update_product("category": category_id,"name": product_name,"slug": product_slug,- "descriptionJson": other_description_json,+ "description": other_description_json,"chargeTaxes": product_charge_taxes,"taxCode": product_tax_rate,"attributes": [{"id": attribute_id, "values": ["Rainbow"]}],@@ -3615,7 +3690,7 @@ def test_update_product(assert data["productErrors"] == []assert data["product"]["name"] == product_nameassert data["product"]["slug"] == product_slug- assert data["product"]["descriptionJson"] == other_description_json+ assert data["product"]["description"] == other_description_jsonassert data["product"]["chargeTaxes"] == product_charge_taxesassert data["product"]["taxType"]["taxCode"] == product_tax_rateassert not data["product"]["category"]["name"] == category.name@@ -3632,6 +3707,85 @@ def test_update_product(updated_webhook_mock.assert_called_once_with(product)+def test_update_and_search_product_by_description(+ staff_api_client,+ category,+ non_default_category,+ product,+ other_description_json,+ permission_manage_products,+ color_attribute,+):+ query = MUTATION_UPDATE_PRODUCT+ other_description_json = json.dumps(other_description_json)++ product_id = graphene.Node.to_global_id("Product", product.pk)+ category_id = graphene.Node.to_global_id("Category", non_default_category.pk)+ product_name = "updated name"+ product_slug = "updated-product"++ variables = {+ "productId": product_id,+ "input": {+ "category": category_id,+ "name": product_name,+ "slug": product_slug,+ "description": other_description_json,+ },+ }++ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)+ data = content["data"]["productUpdate"]+ assert not data["productErrors"]+ assert data["product"]["name"] == product_name+ assert data["product"]["slug"] == product_slug+ assert data["product"]["description"] == other_description_json+++def test_update_product_without_description_clear_description_plaintext(+ staff_api_client,+ category,+ non_default_category,+ product,+ other_description_json,+ permission_manage_products,+ color_attribute,+):+ query = MUTATION_UPDATE_PRODUCT+ description_plaintext = "some desc"+ product.description_plaintext = description_plaintext+ product.save()+ product_id = graphene.Node.to_global_id("Product", product.pk)+ category_id = graphene.Node.to_global_id("Category", non_default_category.pk)+ product_name = "updated name"+ product_slug = "updated-product"++ variables = {+ "productId": product_id,+ "input": {+ "category": category_id,+ "name": product_name,+ "slug": product_slug,+ },+ }++ response = staff_api_client.post_graphql(+ query, variables, permissions=[permission_manage_products]+ )+ content = get_graphql_content(response)+ data = content["data"]["productUpdate"]+ assert not data["productErrors"]+ assert data["product"]["name"] == product_name+ assert data["product"]["slug"] == product_slug+ assert data["product"]["description"] == "{}"++ product.refresh_from_db()+ assert product.description_plaintext == ""++@patch("saleor.plugins.manager.PluginsManager.product_updated")def test_update_product_with_file_attribute_value(updated_webhook_mock,@@ -6349,19 +6503,19 @@ def test_collections_query_with_filter(id=1,name="Collection1",slug="collection-published1",- description="Test description",+ description=dummy_editorjs("Test description"),),Collection(id=2,name="Collection2",slug="collection-published2",- description="Test description",+ description=dummy_editorjs("Test description"),),Collection(id=3,name="Collection3",slug="collection-unpublished",- description="Test description",+ description=dummy_editorjs("Test description"),),])@@ -6463,17 +6617,24 @@ def test_categories_query_with_filter(permission_manage_products,):Category.objects.create(- id=1, name="Category1", slug="slug_category1", description="Description cat1"+ id=1,+ name="Category1",+ slug="slug_category1",+ description=dummy_editorjs("Description cat1."),)Category.objects.create(- id=2, name="Category2", slug="slug_category2", description="Description cat2"+ id=2,+ name="Category2",+ slug="slug_category2",+ description=dummy_editorjs("Description cat2."),)+Category.objects.create(id=3,name="SubCategory",slug="slug_subcategory",parent=Category.objects.get(name="Category1"),- description="Subcategory_description of cat1",+ description=dummy_editorjs("Subcategory_description of cat1."),)variables = {"filter": category_filter}staff_api_client.user.user_permissions.add(permission_manage_products)@@ -6532,7 +6693,9 @@ def test_categories_query_with_sort(product_type,):cat1 = Category.objects.create(- name="Cat1", slug="slug_category1", description="Description cat1"+ name="Cat1",+ slug="slug_category1",+ description=dummy_editorjs("Description cat1."),)Product.objects.create(name="Test",@@ -6541,19 +6704,21 @@ def test_categories_query_with_sort(category=cat1,)Category.objects.create(- name="Cat2", slug="slug_category2", description="Description cat2"+ name="Cat2",+ slug="slug_category2",+ description=dummy_editorjs("Description cat2."),)Category.objects.create(name="SubCat",slug="slug_subcategory1",parent=Category.objects.get(name="Cat1"),- description="Subcategory_description of cat1",+ description=dummy_editorjs("Subcategory_description of cat1."),)subsubcat = Category.objects.create(name="SubSubCat",slug="slug_subcategory2",parent=Category.objects.get(name="SubCat"),- description="Subcategory_description of cat1",+ description=dummy_editorjs("Subcategory_description of cat1."),)Product.objects.create(name="Test2",diff --git a/saleor/graphql/product/tests/test_product_filtering_and_sorting_with_channels.py b/saleor/graphql/product/tests/test_product_filtering_and_sorting_with_channels.pyindex d1eb0d2eab..ae5efe8178 100644--- a/saleor/graphql/product/tests/test_product_filtering_and_sorting_with_channels.py+++ b/saleor/graphql/product/tests/test_product_filtering_and_sorting_with_channels.py@@ -11,6 +11,7 @@ from ....product.models import (ProductVariant,ProductVariantChannelListing,)+from ....tests.utils import dummy_editorjsfrom ...channel.filters import LACK_OF_CHANNEL_IN_FILTERING_MSGfrom ...channel.sorters import LACK_OF_CHANNEL_IN_SORTING_MSGfrom ...tests.utils import assert_graphql_error_with_message, get_graphql_content@@ -26,7 +27,7 @@ def products_for_sorting_with_channels(category, channel_USD, channel_PLN):slug="prod1",category=category,product_type=product_type,- description="desc1",+ description=dummy_editorjs("Test description 1."),),Product(name="ProductProduct1",@@ -45,14 +46,14 @@ def products_for_sorting_with_channels(category, channel_USD, channel_PLN):slug="prod2",category=category,product_type=product_type,- description="desc2",+ description=dummy_editorjs("Test description 2."),),Product(name="Product3",slug="prod3",category=category,product_type=product_type,- description="desc3",+ description=dummy_editorjs("Test description 3."),),])diff --git a/saleor/graphql/product/tests/test_product_pagination.py b/saleor/graphql/product/tests/test_product_pagination.pyindex 81d79e2f03..0b804e88b9 100644--- a/saleor/graphql/product/tests/test_product_pagination.py+++ b/saleor/graphql/product/tests/test_product_pagination.py@@ -15,6 +15,7 @@ from ....product.models import (ProductVariant,ProductVariantChannelListing,)+from ....tests.utils import dummy_editorjsfrom ....warehouse.models import Stockfrom ...tests.utils import get_graphql_content@@ -304,7 +305,7 @@ def products_for_pagination(slug="prod1",category=category,product_type=product_type2,- description="desc1",+ description=dummy_editorjs("Test description 1."),),Product(name="ProductProduct1",@@ -323,14 +324,14 @@ def products_for_pagination(slug="prod2",category=category,product_type=product_type,- description="desc2",+ description=dummy_editorjs("Test description 2."),),Product(name="Product3",slug="prod3",category=category,product_type=product_type2,- description="desc3",+ description=dummy_editorjs("Test description 3."),),])diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.pyindex ad71eed936..7d4499f2e0 100644--- a/saleor/graphql/product/types/products.py+++ b/saleor/graphql/product/types/products.py@@ -430,6 +430,12 @@ class ProductVariant(ChannelContextTypeWithMetadata, CountableDjangoObjectType):@key(fields="id")class Product(ChannelContextTypeWithMetadata, CountableDjangoObjectType):+ description_json = graphene.String(+ description="Description of the product (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )url = graphene.String(description="The storefront URL for the product.",required=True,@@ -497,7 +503,6 @@ class Product(ChannelContextTypeWithMetadata, CountableDjangoObjectType):"category","charge_taxes","description",- "description_json","id","name","slug",@@ -881,6 +886,12 @@ class ProductType(CountableDjangoObjectType):@key(fields="id")class Collection(ChannelContextTypeWithMetadata, CountableDjangoObjectType):+ description_json = graphene.String(+ description="Description of the collection (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )products = ChannelContextFilterConnectionField(Product,filter=ProductFilterInput(description="Filtering options for products."),@@ -905,7 +916,6 @@ class Collection(ChannelContextTypeWithMetadata, CountableDjangoObjectType):description = "Represents a collection of products."only_fields = ["description",- "description_json","id","name","seo_description",@@ -949,6 +959,12 @@ class Collection(ChannelContextTypeWithMetadata, CountableDjangoObjectType):@key(fields="id")class Category(CountableDjangoObjectType):+ description_json = graphene.String(+ description="Description of the category (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )ancestors = PrefetchingConnectionField(lambda: Category, description="List of ancestors of the category.")@@ -979,7 +995,6 @@ class Category(CountableDjangoObjectType):)only_fields = ["description",- "description_json","id","level","name",diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 1b6ec980db..75e12bea60 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -671,13 +671,13 @@ type Category implements Node & ObjectWithMetadata {seoDescription: Stringid: ID!name: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!slug: String!parent: Categorylevel: Int!privateMetadata: [MetadataItem]!metadata: [MetadataItem]!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")ancestors(before: String, after: String, first: Int, last: Int): CategoryCountableConnectionproducts(channel: String, before: String, after: String, first: Int, last: Int): ProductCountableConnectionurl: String @deprecated(reason: "This field will be removed after 2020-07-31.")@@ -721,8 +721,7 @@ input CategoryFilterInput {}input CategoryInput {- description: String- descriptionJson: JSONString+ description: JSONStringname: Stringslug: Stringseo: SeoInput@@ -747,8 +746,8 @@ type CategoryTranslatableContent implements Node {seoDescription: Stringid: ID!name: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")translation(languageCode: LanguageCodeEnum!): CategoryTranslationcategory: Category}@@ -764,9 +763,9 @@ type CategoryTranslation implements Node {seoDescription: Stringid: ID!name: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!language: LanguageDisplay!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")}type CategoryUpdate {@@ -1051,11 +1050,11 @@ type Collection implements Node & ObjectWithMetadata {seoDescription: Stringid: ID!name: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!slug: String!privateMetadata: [MetadataItem]!metadata: [MetadataItem]!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")products(filter: ProductFilterInput, sortBy: ProductOrder, before: String, after: String, first: Int, last: Int): ProductCountableConnectionbackgroundImage(size: Int): Imagetranslation(languageCode: LanguageCodeEnum!): CollectionTranslation@@ -1122,8 +1121,7 @@ input CollectionCreateInput {isPublished: Booleanname: Stringslug: String- description: String- descriptionJson: JSONString+ description: JSONStringbackgroundImage: UploadbackgroundImageAlt: Stringseo: SeoInput@@ -1165,8 +1163,7 @@ input CollectionInput {isPublished: Booleanname: Stringslug: String- description: String- descriptionJson: JSONString+ description: JSONStringbackgroundImage: UploadbackgroundImageAlt: Stringseo: SeoInput@@ -1208,8 +1205,8 @@ type CollectionTranslatableContent implements Node {seoDescription: Stringid: ID!name: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")translation(languageCode: LanguageCodeEnum!): CollectionTranslationcollection: Collection}@@ -1225,9 +1222,9 @@ type CollectionTranslation implements Node {seoDescription: Stringid: ID!name: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!language: LanguageDisplay!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")}type CollectionUpdate {@@ -3266,8 +3263,7 @@ type Page implements Node & ObjectWithMetadata {seoDescription: Stringid: ID!title: String!- content: String!- contentJson: JSONString!+ content: JSONString!publicationDate: DateisPublished: Boolean!slug: String!@@ -3275,6 +3271,7 @@ type Page implements Node & ObjectWithMetadata {created: DateTime!privateMetadata: [MetadataItem]!metadata: [MetadataItem]!+ contentJson: String! @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.")translation(languageCode: LanguageCodeEnum!): PageTranslationattributes: [SelectedAttribute!]!}@@ -3323,8 +3320,7 @@ type PageCreate {input PageCreateInput {slug: Stringtitle: String- content: String- contentJson: JSONString+ content: JSONStringattributes: [AttributeValueInput!]isPublished: BooleanpublicationDate: String@@ -3370,8 +3366,7 @@ type PageInfo {input PageInput {slug: Stringtitle: String- content: String- contentJson: JSONString+ content: JSONStringattributes: [AttributeValueInput!]isPublished: BooleanpublicationDate: String@@ -3402,8 +3397,8 @@ type PageTranslatableContent implements Node {seoDescription: Stringid: ID!title: String!- content: String!- contentJson: JSONString!+ content: JSONString!+ contentJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.")translation(languageCode: LanguageCodeEnum!): PageTranslationpage: Page}@@ -3419,17 +3414,16 @@ type PageTranslation implements Node {seoDescription: Stringid: ID!title: String!- content: String!- contentJson: JSONString!+ content: JSONString!language: LanguageDisplay!+ contentJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.")}input PageTranslationInput {seoTitle: StringseoDescription: Stringtitle: String- content: String- contentJson: JSONString+ content: JSONString}type PageType implements Node & ObjectWithMetadata {@@ -3797,8 +3791,7 @@ type Product implements Node & ObjectWithMetadata {seoTitle: StringseoDescription: Stringname: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!productType: ProductType!slug: String!category: Category@@ -3809,6 +3802,7 @@ type Product implements Node & ObjectWithMetadata {rating: FloatprivateMetadata: [MetadataItem]!metadata: [MetadataItem]!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")url: String! @deprecated(reason: "This field will be removed after 2020-07-31.")thumbnail(size: Int): Imagepricing: ProductPricingInfo@@ -3918,8 +3912,7 @@ input ProductCreateInput {category: IDchargeTaxes: Booleancollections: [ID]- description: String- descriptionJson: JSONString+ description: JSONStringname: Stringslug: StringtaxCode: String@@ -4050,8 +4043,7 @@ input ProductInput {category: IDchargeTaxes: Booleancollections: [ID]- description: String- descriptionJson: JSONString+ description: JSONStringname: Stringslug: StringtaxCode: String@@ -4104,8 +4096,8 @@ type ProductTranslatableContent implements Node {seoTitle: StringseoDescription: Stringname: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")translation(languageCode: LanguageCodeEnum!): ProductTranslationproduct: Product}@@ -4121,9 +4113,9 @@ type ProductTranslation implements Node {seoTitle: StringseoDescription: Stringname: String!- description: String!- descriptionJson: JSONString!+ description: JSONString!language: LanguageDisplay!+ descriptionJson: String @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.")}type ProductType implements Node & ObjectWithMetadata {@@ -5289,8 +5281,7 @@ input TranslationInput {seoTitle: StringseoDescription: Stringname: String- description: String- descriptionJson: JSONString+ description: JSONString}scalar UUIDdiff --git a/saleor/graphql/translations/mutations.py b/saleor/graphql/translations/mutations.pyindex 85f29b076f..1cc3eec1b4 100644--- a/saleor/graphql/translations/mutations.py+++ b/saleor/graphql/translations/mutations.py@@ -53,8 +53,7 @@ class SeoTranslationInput(graphene.InputObjectType):class TranslationInput(NameTranslationInput, SeoTranslationInput):- description = graphene.String()- description_json = graphene.JSONString()+ description = graphene.JSONString()class CategoryTranslate(BaseTranslateMutation):@@ -269,8 +268,7 @@ class MenuItemTranslate(BaseTranslateMutation):class PageTranslationInput(SeoTranslationInput):title = graphene.String()- content = graphene.String()- content_json = graphene.JSONString()+ content = graphene.JSONString()class PageTranslate(BaseTranslateMutation):diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.pyindex 038dcc73c8..444c82efa4 100644--- a/saleor/graphql/translations/types.py+++ b/saleor/graphql/translations/types.py@@ -22,7 +22,6 @@ EXTENDED_TRANSLATABLE_FIELDS = ["id","name","description",- "description_json","seo_title","seo_description",]@@ -130,6 +129,13 @@ class ProductVariantTranslatableContent(CountableDjangoObjectType):class ProductTranslation(BaseTranslationType):+ description_json = graphene.String(+ description="Translated description of the product (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )+class Meta:model = product_models.ProductTranslationinterfaces = [graphene.relay.Node]@@ -137,6 +143,12 @@ class ProductTranslation(BaseTranslationType):class ProductTranslatableContent(CountableDjangoObjectType):+ description_json = graphene.String(+ description="Description of the product (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )translation = TranslationField(ProductTranslation, type_name="product")product = graphene.Field("saleor.graphql.product.types.products.Product",@@ -154,6 +166,13 @@ class ProductTranslatableContent(CountableDjangoObjectType):class CollectionTranslation(BaseTranslationType):+ description_json = graphene.String(+ description="Translated description of the product (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )+class Meta:model = product_models.CollectionTranslationinterfaces = [graphene.relay.Node]@@ -161,6 +180,12 @@ class CollectionTranslation(BaseTranslationType):class CollectionTranslatableContent(CountableDjangoObjectType):+ description_json = graphene.String(+ description="Description of the collection (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )translation = TranslationField(CollectionTranslation, type_name="collection")collection = graphene.Field("saleor.graphql.product.types.products.Collection",@@ -181,6 +206,13 @@ class CollectionTranslatableContent(CountableDjangoObjectType):class CategoryTranslation(BaseTranslationType):+ description_json = graphene.String(+ description="Translated description of the product (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )+class Meta:model = product_models.CategoryTranslationinterfaces = [graphene.relay.Node]@@ -188,6 +220,12 @@ class CategoryTranslation(BaseTranslationType):class CategoryTranslatableContent(CountableDjangoObjectType):+ description_json = graphene.String(+ description="Description of the category (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `description` field instead."+ ),+ )translation = TranslationField(CategoryTranslation, type_name="category")category = graphene.Field("saleor.graphql.product.types.products.Category",@@ -205,12 +243,18 @@ class CategoryTranslatableContent(CountableDjangoObjectType):class PageTranslation(BaseTranslationType):+ content_json = graphene.String(+ description="Translated description of the page (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `content` field instead."+ ),+ )+class Meta:model = page_models.PageTranslationinterfaces = [graphene.relay.Node]only_fields = ["content",- "content_json","id","seo_description","seo_title",@@ -219,6 +263,12 @@ class PageTranslation(BaseTranslationType):class PageTranslatableContent(CountableDjangoObjectType):+ content_json = graphene.String(+ description="Content of the page (JSON).",+ deprecation_reason=(+ "Will be removed in Saleor 4.0. Use the `content` field instead."+ ),+ )translation = TranslationField(PageTranslation, type_name="page")page = graphene.Field("saleor.graphql.page.types.Page",@@ -233,7 +283,6 @@ class PageTranslatableContent(CountableDjangoObjectType):interfaces = [graphene.relay.Node]only_fields = ["content",- "content_json","id","seo_description","seo_title",diff --git a/saleor/page/migrations/0016_auto_20201112_0904.py b/saleor/page/migrations/0016_auto_20201112_0904.pyindex 283003f5e5..fd8dd83d20 100644--- a/saleor/page/migrations/0016_auto_20201112_0904.py+++ b/saleor/page/migrations/0016_auto_20201112_0904.py@@ -3,7 +3,7 @@from django.db import migrationsimport saleor.core.db.fields-import saleor.core.sanitizers.editorjs_sanitizer+import saleor.core.utils.editorjsclass Migration(migrations.Migration):@@ -19,7 +19,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),migrations.AlterField(@@ -28,7 +28,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),]diff --git a/saleor/page/migrations/0018_migrate_content_json_into_content.py b/saleor/page/migrations/0018_migrate_content_json_into_content.pynew file mode 100644index 0000000000..9ea8146837--- /dev/null+++ b/saleor/page/migrations/0018_migrate_content_json_into_content.py@@ -0,0 +1,59 @@+# Generated by Django 3.1 on 2021-01-07 12:07++from django.db import migrations+from django.db.models import F++import saleor.core.db.fields+import saleor.core.utils.editorjs+++def clean_content_field(apps, schema_editor):+ Page = apps.get_model("page", "Page")+ PageTranslation = apps.get_model("page", "PageTranslation")++ Page.objects.all().update(content="{}")+ PageTranslation.objects.all().update(content="{}")+++def migrate_content_json_into_content_field(apps, schema_editor):+ Page = apps.get_model("page", "Page")+ PageTranslation = apps.get_model("page", "PageTranslation")++ Page.objects.all().update(content=F("content_json"))+ PageTranslation.objects.all().update(content=F("content_json"))+++class Migration(migrations.Migration):++ dependencies = [+ ("page", "0017_pagetype"),+ ]++ operations = [+ migrations.RunPython(+ clean_content_field,+ migrations.RunPython.noop,+ ),+ migrations.AlterField(+ model_name="page",+ name="content",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.AlterField(+ model_name="pagetranslation",+ name="content",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.RunPython(+ migrate_content_json_into_content_field,+ migrations.RunPython.noop,+ ),+ ]diff --git a/saleor/page/models.py b/saleor/page/models.pyindex 6795763d81..3d606870c4 100644--- a/saleor/page/models.py+++ b/saleor/page/models.py@@ -3,7 +3,7 @@ from django.db import modelsfrom ..core.db.fields import SanitizedJSONFieldfrom ..core.models import ModelWithMetadata, PublishableModelfrom ..core.permissions import PagePermissions, PageTypePermissions-from ..core.sanitizers.editorjs_sanitizer import clean_editor_js+from ..core.utils.editorjs import clean_editor_jsfrom ..core.utils.translations import TranslationProxyfrom ..seo.models import SeoModel, SeoModelTranslation@@ -14,7 +14,7 @@ class Page(ModelWithMetadata, SeoModel, PublishableModel):page_type = models.ForeignKey("PageType", related_name="pages", on_delete=models.CASCADE)- content = models.TextField(blank=True)+ content = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)content_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)@@ -36,7 +36,7 @@ class PageTranslation(SeoModelTranslation):Page, related_name="translations", on_delete=models.CASCADE)title = models.CharField(max_length=255, blank=True)- content = models.TextField(blank=True)+ content = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)content_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)diff --git a/saleor/product/migrations/0131_auto_20201112_0904.py b/saleor/product/migrations/0131_auto_20201112_0904.pyindex f51969d379..a912c947a1 100644--- a/saleor/product/migrations/0131_auto_20201112_0904.py+++ b/saleor/product/migrations/0131_auto_20201112_0904.py@@ -3,7 +3,7 @@from django.db import migrationsimport saleor.core.db.fields-import saleor.core.sanitizers.editorjs_sanitizer+import saleor.core.utils.editorjsclass Migration(migrations.Migration):@@ -19,7 +19,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),migrations.AlterField(@@ -28,7 +28,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),migrations.AlterField(@@ -37,7 +37,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),migrations.AlterField(@@ -46,7 +46,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),migrations.AlterField(@@ -55,7 +55,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),migrations.AlterField(@@ -64,7 +64,7 @@ class Migration(migrations.Migration):field=saleor.core.db.fields.SanitizedJSONField(blank=True,default=dict,- sanitizer=saleor.core.sanitizers.editorjs_sanitizer.clean_editor_js,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,),),]diff --git a/saleor/product/migrations/0138_migrate_description_json_into_description.py b/saleor/product/migrations/0138_migrate_description_json_into_description.pynew file mode 100644index 0000000000..799b994026--- /dev/null+++ b/saleor/product/migrations/0138_migrate_description_json_into_description.py@@ -0,0 +1,121 @@+# Generated by Django 3.1 on 2021-01-07 11:59++from django.db import migrations+from django.db.models import F++import saleor.core.db.fields+import saleor.core.utils.editorjs+++def clean_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.all().update(description="{}")+++def migrate_description_json_into_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.all().update(description=F("description_json"))+++class Migration(migrations.Migration):++ dependencies = [+ ("product", "0137_drop_attribute_models"),+ ]++ operations = [+ migrations.RunPython(+ clean_description_field,+ migrations.RunPython.noop,+ ),+ migrations.AlterField(+ model_name="category",+ name="description",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.AlterField(+ model_name="categorytranslation",+ name="description",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.AlterField(+ model_name="collection",+ name="description",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.AlterField(+ model_name="collectiontranslation",+ name="description",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.AlterField(+ model_name="product",+ name="description",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.AlterField(+ model_name="producttranslation",+ name="description",+ field=saleor.core.db.fields.SanitizedJSONField(+ blank=True,+ default=dict,+ sanitizer=saleor.core.utils.editorjs.clean_editor_js,+ ),+ ),+ migrations.RunPython(+ migrate_description_json_into_description_field,+ migrations.RunPython.noop,+ ),+ ]diff --git a/saleor/product/migrations/0139_description_vector_search.py b/saleor/product/migrations/0139_description_vector_search.pynew file mode 100644index 0000000000..5df0a68022--- /dev/null+++ b/saleor/product/migrations/0139_description_vector_search.py@@ -0,0 +1,75 @@+# Generated by Django 3.1.5 on 2021-01-14 08:31++import django.contrib.postgres.indexes+import django.contrib.postgres.search+from django.db import migrations, models+++def parse_description_json_to_string(description):+ string = ""+ blocks = description.get("blocks")+ if not blocks or not isinstance(blocks, list):+ return ""+ for block in blocks:+ block_type = block["type"]+ if block_type == "list":+ for item in block["data"].get("items"):+ if not item:+ continue+ string += item+ else:+ text = block["data"].get("text")+ if not text:+ continue+ string += text+ return string+++def migrate_description_into_description_plaintext(apps, schema):+ Product = apps.get_model("product", "Product")+ for product in Product.objects.iterator():+ product.description_plaintext = parse_description_json_to_string(+ product.description+ )+ product.save()+++class Migration(migrations.Migration):++ dependencies = [+ ("product", "0138_migrate_description_json_into_description"),+ ]++ operations = [+ migrations.AddField(+ model_name="product",+ name="description_plaintext",+ field=models.TextField(blank=True, default=""),+ ),+ migrations.AddField(+ model_name="product",+ name="search_vector",+ field=django.contrib.postgres.search.SearchVectorField(+ blank=True, null=True+ ),+ ),+ migrations.AddIndex(+ model_name="product",+ index=django.contrib.postgres.indexes.GinIndex(+ fields=["search_vector"], name="product_pro_search__e78047_gin"+ ),+ ),+ migrations.RunSQL(+ """+ CREATE TRIGGER title_vector_update BEFORE INSERT OR UPDATE+ ON product_product FOR EACH ROW EXECUTE PROCEDURE+ tsvector_update_trigger(+ 'search_vector', 'pg_catalog.english', 'description_plaintext'+ );+ """+ ),+ migrations.RunPython(+ migrate_description_into_description_plaintext,+ migrations.RunPython.noop,+ ),+ ]diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 84bf54a8a3..135886fe0e 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -4,8 +4,9 @@ from uuid import uuid4from django.conf import settingsfrom django.contrib.postgres.aggregates import StringAgg+from django.contrib.postgres.indexes import GinIndex+from django.contrib.postgres.search import SearchVectorFieldfrom django.db import models-from django.db.models import JSONField # type: ignorefrom django.db.models import (BooleanField,Case,@@ -18,6 +19,7 @@ from django.db.models import (Q,Subquery,Sum,+ TextField,Value,When,)@@ -36,9 +38,9 @@ from ..channel.models import Channelfrom ..core.db.fields import SanitizedJSONFieldfrom ..core.models import ModelWithMetadata, PublishableModel, SortableModelfrom ..core.permissions import ProductPermissions, ProductTypePermissions-from ..core.sanitizers.editorjs_sanitizer import clean_editor_jsfrom ..core.utils import build_absolute_urifrom ..core.utils.draftjs import json_content_to_raw_text+from ..core.utils.editorjs import clean_editor_jsfrom ..core.utils.translations import TranslationProxyfrom ..core.weight import WeightUnits, zero_weightfrom ..discount import DiscountInfo@@ -57,7 +59,9 @@ 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 = models.TextField(blank=True)+ description = SanitizedJSONField(+ blank=True, default=dict, sanitizer=clean_editor_js+ )description_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)@@ -83,7 +87,9 @@ class CategoryTranslation(SeoModelTranslation):Category, related_name="translations", on_delete=models.CASCADE)name = models.CharField(max_length=128)- description = models.TextField(blank=True)+ description = SanitizedJSONField(+ blank=True, default=dict, sanitizer=clean_editor_js+ )description_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)@@ -308,7 +314,12 @@ class Product(SeoModel, ModelWithMetadata):)name = models.CharField(max_length=250)slug = models.SlugField(max_length=255, unique=True, allow_unicode=True)- description = models.TextField(blank=True)+ description = SanitizedJSONField(+ blank=True, default=dict, sanitizer=clean_editor_js+ )+ description_plaintext = TextField(blank=True, default="")+ search_vector = SearchVectorField(null=True, blank=True)+description_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)@@ -342,6 +353,7 @@ class Product(SeoModel, ModelWithMetadata):permissions = ((ProductPermissions.MANAGE_PRODUCTS.codename, "Manage products."),)+ indexes = [GinIndex(fields=["search_vector"])]def __iter__(self):if not hasattr(self, "__variants"):@@ -362,7 +374,7 @@ class Product(SeoModel, ModelWithMetadata):@propertydef plain_text_description(self) -> str:- return json_content_to_raw_text(self.description_json)+ return json_content_to_raw_text(self.description)def get_first_image(self):images = list(self.images.all())@@ -379,7 +391,9 @@ class ProductTranslation(SeoModelTranslation):Product, related_name="translations", on_delete=models.CASCADE)name = models.CharField(max_length=250)- description = models.TextField(blank=True)+ description = SanitizedJSONField(+ blank=True, default=dict, sanitizer=clean_editor_js+ )description_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)@@ -698,7 +712,9 @@ class Collection(SeoModel, ModelWithMetadata):upload_to="collection-backgrounds", blank=True, null=True)background_image_alt = models.CharField(max_length=128, blank=True)- description = models.TextField(blank=True)+ description = SanitizedJSONField(+ blank=True, default=dict, sanitizer=clean_editor_js+ )description_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)@@ -741,7 +757,9 @@ class CollectionTranslation(SeoModelTranslation):Collection, related_name="translations", on_delete=models.CASCADE)name = models.CharField(max_length=128)- description = models.TextField(blank=True)+ description = SanitizedJSONField(+ blank=True, default=dict, sanitizer=clean_editor_js+ )description_json = SanitizedJSONField(blank=True, default=dict, sanitizer=clean_editor_js)diff --git a/saleor/product/tests/test_translation.py b/saleor/product/tests/test_translation.pyindex 4d3304132a..20d47e3e76 100644--- a/saleor/product/tests/test_translation.py+++ b/saleor/product/tests/test_translation.py@@ -1,6 +1,7 @@import pytestfrom ...attribute.models import AttributeTranslation, AttributeValueTranslation+from ...tests.utils import dummy_editorjsfrom ..models import (CategoryTranslation,CollectionTranslation,@@ -15,7 +16,7 @@ def product_translation_pl(product):language_code="pl",product=product,name="Polish name",- description="Polish description",+ description=dummy_editorjs("Polish description."),)@@ -33,7 +34,7 @@ def test_translation(product, settings, product_translation_fr):settings.LANGUAGE_CODE = "fr"assert product.translated.name == "French name"- assert product.translated.description == "French description"+ assert product.translated.description == dummy_editorjs("French description.")def test_translation_str_returns_str_of_instance(@@ -80,7 +81,7 @@ def test_collection_translation(settings, collection):def test_category_translation(settings, category):settings.LANGUAGE_CODE = "fr"french_name = "French name"- french_description = "French description"+ french_description = dummy_editorjs("French description.")CategoryTranslation.objects.create(language_code="fr",name=french_name,diff --git a/saleor/search/__init__.py b/saleor/search/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/search/backends/__init__.py b/saleor/search/backends/__init__.pydeleted file mode 100755index e69de29bb2..0000000000diff --git a/saleor/search/backends/picker.py b/saleor/search/backends/picker.pydeleted file mode 100644index fcbe873084..0000000000--- a/saleor/search/backends/picker.py+++ /dev/null@@ -1,10 +0,0 @@-from django.conf import settings-from django.utils.module_loading import import_module # type: ignore---def pick_backend():- """Return the currently configured storefront search function.-- Returns a callable that accepts the search phrase.- """- return import_module(settings.SEARCH_BACKEND).search_storefrontdiff --git a/saleor/search/backends/postgresql.py b/saleor/search/backends/postgresql.pydeleted file mode 100644index 4a1093d3fa..0000000000--- a/saleor/search/backends/postgresql.py+++ /dev/null@@ -1,5 +0,0 @@-from . import postgresql_storefront---def search_storefront(phrase):- return postgresql_storefront.search(phrase)diff --git a/saleor/search/backends/postgresql_storefront.py b/saleor/search/backends/postgresql_storefront.pydeleted file mode 100644index fadc7f178e..0000000000--- a/saleor/search/backends/postgresql_storefront.py+++ /dev/null@@ -1,24 +0,0 @@-from django.contrib.postgres.search import TrigramSimilarity-from django.db.models import Q--from ...product.models import Product---def search(phrase):- """Return matching products for storefront views.-- Fuzzy storefront search that is resistant to small typing errors made- by user. Name is matched using trigram similarity, description uses- standard postgres full text search.-- Args:- phrase (str): searched phrase-- """- name_sim = TrigramSimilarity("name", phrase)- ft_in_description = Q(description__search=phrase)- ft_by_sku = Q(variants__sku__search=phrase)- name_similar = Q(name_sim__gt=0.2)- return Product.objects.annotate(name_sim=name_sim).filter(- (ft_in_description | name_similar | ft_by_sku)- )diff --git a/saleor/search/management/__init__.py b/saleor/search/management/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/search/management/commands/__init__.py b/saleor/search/management/commands/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/search/migrations/__init__.py b/saleor/search/migrations/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/settings.py b/saleor/settings.pyindex bf810fdfb8..042ee60dd3 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -246,7 +246,6 @@ INSTALLED_APPS = ["saleor.invoice","saleor.seo","saleor.shipping",- "saleor.search","saleor.site","saleor.page","saleor.payment",@@ -465,7 +464,6 @@ PLACEHOLDER_IMAGES = {DEFAULT_PLACEHOLDER = "images/placeholder255x255.png"-SEARCH_BACKEND = "saleor.search.backends.postgresql"AUTHENTICATION_BACKENDS = ["saleor.core.auth_backend.JSONWebTokenBackend",diff --git a/saleor/static/populatedb_data.json b/saleor/static/populatedb_data.jsonindex e0a00cb598..7de2c85c91 100644--- a/saleor/static/populatedb_data.json+++ b/saleor/static/populatedb_data.json@@ -8,8 +8,7 @@"seo_description": "","name": "Accessories","slug": "accessories",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": ""@@ -36,8 +35,7 @@"seo_description": "","name": "Groceries","slug": "groceries",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": ""@@ -64,8 +62,7 @@"seo_description": "","name": "Apparel","slug": "apparel",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": ""@@ -92,8 +89,7 @@"seo_description": "","name": "T-shirts","slug": "t-shirts",- "description": "",- "description_json": {},+ "description": {},"parent": 9,"background_image": "category-backgrounds/apparel_aQjIlZr.jpg","background_image_alt": "",@@ -113,8 +109,7 @@"seo_description": "","name": "Polo Shirts","slug": "polo-shirts",- "description": "",- "description_json": {},+ "description": {},"parent": 9,"background_image": "category-backgrounds/apparel_HuImTaR.jpg","background_image_alt": "",@@ -134,8 +129,7 @@"seo_description": "","name": "Hoodies","slug": "hoodies",- "description": "",- "description_json": {},+ "description": {},"parent": 9,"background_image": "category-backgrounds/apparel_6ziH1ON.jpg","background_image_alt": "",@@ -155,8 +149,7 @@"seo_description": "","name": "Footwear","slug": "footwear",- "description": "",- "description_json": {},+ "description": {},"parent": 9,"background_image": "category-backgrounds/apparel_awJisre.jpg","background_image_alt": "",@@ -176,8 +169,7 @@"seo_description": "","name": "Juices","slug": "juices",- "description": "",- "description_json": {},+ "description": {},"parent": 8,"background_image": "category-backgrounds/groceries_k5IaCqp.jpg","background_image_alt": "",@@ -197,8 +189,7 @@"seo_description": "","name": "Alcohol","slug": "alcohol",- "description": "",- "description_json": {},+ "description": {},"parent": 8,"background_image": "category-backgrounds/groceries_f5xedIS.jpg","background_image_alt": "",@@ -218,8 +209,7 @@"seo_description": "","name": "Paints","slug": "paints",- "description": "",- "description_json": {},+ "description": {},"parent": 7,"background_image": "category-backgrounds/accessories_HMorc9P.jpg","background_image_alt": "",@@ -239,8 +229,7 @@"seo_description": "","name": "Homewares","slug": "homewares",- "description": "",- "description_json": {},+ "description": {},"parent": 7,"background_image": "category-backgrounds/accessories_tDJUL1J.jpg","background_image_alt": "",@@ -260,8 +249,7 @@"seo_description": "","name": "Audiobooks","slug": "ebooks",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": ""@@ -446,8 +434,7 @@"product_type": 7,"name": "Nebula Night Sky Paint","slug": "nebula-night-sky-paint",- "description": "Tonight, my love, let us take fat brushes and paint the skies with the shades of nebula tides. Get the dark, moody shades of the ether.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Tonight, my love, let us take fat brushes and paint the skies with the shades of nebula tides. Get the dark, moody shades of the ether."@@ -475,8 +462,7 @@"product_type": 7,"name": "Space Dust Navy Paint","slug": "space-dust-navy-paint",- "description": "The rich, deep hue of space dust. Vacuum packed and airlocked for long-lasting freshness of color.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "The rich, deep hue of space dust. Vacuum packed and airlocked for long-lasting freshness of color."@@ -504,8 +490,7 @@"product_type": 7,"name": "Red Dwarf Red Paint","slug": "red-dwarf-red-paint",- "description": "We are all connected to the universe, because every cell in our bodies was cooked in the hearts of dying stars. Red Dwarf Paint: the color of Carl Sagan’s dreams.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "We are all connected to the universe, because every cell in our bodies was cooked in the hearts of dying stars. Red Dwarf Paint: the color of Carl Sagan’s dreams."@@ -533,8 +518,7 @@"product_type": 7,"name": "Light Speed Yellow Paint","slug": "light-speed-yellow-paint",- "description": "There is life in outer space. This vibrant light speed yellow paint brings life to any surface. Goes on easy and dries at light speed.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "There is life in outer space. This vibrant light speed yellow paint brings life to any surface. Goes on easy and dries at light speed."@@ -562,8 +546,7 @@"product_type": 7,"name": "Hyperspace Turquoise Paint","slug": "hyperspace-turquoise-paint",- "description": "Turquoise is the new black. No more gloomy night skies, brighten up your evenings with hyperspace paint.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Turquoise is the new black. No more gloomy night skies, brighten up your evenings with hyperspace paint."@@ -591,8 +574,7 @@"product_type": 9,"name": "Orange Juice","slug": "orange-juice",- "description": "Fell from a tree straight into the bottle. No additives, no preservatives, just the refreshing taste of pure sun-kissed Californian oranges.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Fell from a tree straight into the bottle. No additives, no preservatives, just the refreshing taste of pure sun-kissed Californian oranges."@@ -620,8 +602,7 @@"product_type": 9,"name": "Apple Juice","slug": "apple-juice",- "description": "Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Fell straight from the tree, on to Newton’s head, then into the bottle. The autumn taste of English apples. Brought to you by gravity."@@ -649,8 +630,7 @@"product_type": 9,"name": "Carrot Juice","slug": "carrot-juice",- "description": "Improve your eyesight the natural way with 100% pure, squeezed carrot juice. The sweet, orange nectar of Mother Earth.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Improve your eyesight the natural way with 100% pure, squeezed carrot juice. The sweet, orange nectar of Mother Earth."@@ -678,8 +658,7 @@"product_type": 9,"name": "Banana Juice","slug": "banana-juice",- "description": "Build your protein the natural way, with exotic banana juice made from ripe fruit and packed with all the goodness of the tropical sun.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Build your protein the natural way, with exotic banana juice made from ripe fruit and packed with all the goodness of the tropical sun."@@ -707,8 +686,7 @@"product_type": 9,"name": "Pineapple Juice","slug": "pineapple-juice",- "description": "I can’t stand pineapples, so this one is not for me. They have a weird, fluffy, tangy taste. But if it is your kind of thing, then knock yourself out.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "I can’t stand pineapples, so this one is not for me. They have a weird, fluffy, tangy taste. But if it is your kind of thing, then knock yourself out."@@ -736,8 +714,7 @@"product_type": 9,"name": "Coconut Juice","slug": "coconut-juice",- "description": "Did you know falling coconuts kill 150 people a year? But did you know that coconut juice is the new superfood? You win some, you lose some.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Did you know falling coconuts kill 150 people a year? But did you know that coconut juice is the new superfood? You win some, you lose some."@@ -765,8 +742,7 @@"product_type": 9,"name": "Power Juice","slug": "power-juice",- "description": "Is it a bird? Is a plane? No! It’s some jacked dude who just sucked down a bottle of our brand new power juice! Look at him go!",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Is it a bird? Is a plane? No! It’s some jacked dude who just sucked down a bottle of our brand new power juice! Look at him go!"@@ -794,8 +770,7 @@"product_type": 9,"name": "Green Juice","slug": "green-juice",- "description": "Brussel sprouts, spinach, peas, kale, lettuce, cabbage, zucchini, more brussel sprouts. All the greens you’ll ever need in one delicious juice.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Brussel sprouts, spinach, peas, kale, lettuce, cabbage, zucchini, more brussel sprouts. All the greens you’ll ever need in one delicious juice."@@ -823,8 +798,7 @@"product_type": 9,"name": "Bean Juice","slug": "bean-juice",- "description": "Bean there, drunk that! The energy drink for the health-conscious. Brand new bean juice; from allotment to bottle in under 8 hours.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Bean there, drunk that! The energy drink for the health-conscious. Brand new bean juice; from allotment to bottle in under 8 hours."@@ -852,8 +826,7 @@"product_type": 10,"name": "Red Wine","slug": "red-wine",- "description": "A fine, mature red with a hint of blackberry, an undertone of the alkaline Burgundy soil, a delicate aftertaste of burnt garlic, and a whole lot of grapes.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "A fine, mature red with a hint of blackberry, an undertone of the alkaline Burgundy soil, a delicate aftertaste of burnt garlic, and a whole lot of grapes."@@ -881,8 +854,7 @@"product_type": 10,"name": "White Wine","slug": "white-wine",- "description": "Watch the slow setting sun of a wild summer evening sink into the horizon as you sip white wine that tastes like bittersweet memories of halcyon days.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Watch the slow setting sun of a wild summer evening sink into the horizon as you sip white wine that tastes like bittersweet memories of halcyon days."@@ -910,8 +882,7 @@"product_type": 11,"name": "Seaman Lager","slug": "seaman-lager",- "description": "Find your sea legs and then lose the power to use them with extra strong seaman’s lager. Don’t drink and sail, me hearties!",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Find your sea legs and then lose the power to use them with extra strong seaman’s lager. Don’t drink and sail, me hearties!"@@ -939,8 +910,7 @@"product_type": 11,"name": "Seaman Beer","slug": "seaman-beer",- "description": "Best beer on the seven seas. A dark ale for when the dark clouds gather overhead. The nutty nautical taste that sailors love.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Best beer on the seven seas. A dark ale for when the dark clouds gather overhead. The nutty nautical taste that sailors love."@@ -968,8 +938,7 @@"product_type": 12,"name": "Colored Parrot Cushion","slug": "colored-parrot-cushion",- "description": "Add a little color to your life with a Saleor parrot cushion. Turns any old sofa into a rainbow of classy interior design.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Add a little color to your life with a Saleor parrot cushion. Turns any old sofa into a rainbow of classy interior design."@@ -997,8 +966,7 @@"product_type": 12,"name": "White Parrot Cushion","slug": "white-parrot-cushion",- "description": "Minimalist interiors need simple, sleek soft furnishings. Don’t parrot what others do, set your own monochrome trends with Saleor designs.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Minimalist interiors need simple, sleek soft furnishings. Don’t parrot what others do, set your own monochrome trends with Saleor designs."@@ -1026,8 +994,7 @@"product_type": 13,"name": "Yellow Plimsolls","slug": "yellow-plimsolls",- "description": "Mellow yellow. Step into summer with Saleor. Every time your head goes down, you see these beauties, and your mood bounces right back up.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Mellow yellow. Step into summer with Saleor. Every time your head goes down, you see these beauties, and your mood bounces right back up."@@ -1055,8 +1022,7 @@"product_type": 13,"name": "White Plimsolls","slug": "white-plimsolls",- "description": "PE at school wouldn’t have been such a drag with these on your feet. Slip on the style and stride tall with Saleor branded plimsolls. PE now stands for pretty elegant.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "PE at school wouldn’t have been such a drag with these on your feet. Slip on the style and stride tall with Saleor branded plimsolls. PE now stands for pretty elegant."@@ -1084,8 +1050,7 @@"product_type": 14,"name": "Code Division T-shirt","slug": "code-division-t-shirt",- "description": "Pay homage to the music and art of a Joy Division and Peter Saville, but with a Mirumee twist. Perfect live transmission apparel for dead souls.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Pay homage to the music and art of a Joy Division and Peter Saville, but with a Mirumee twist. Perfect live transmission apparel for dead souls."@@ -1113,8 +1078,7 @@"product_type": 14,"name": "Polo Shirt","slug": "polo-shirt",- "description": "Ever have those days where you feel a bit geometric? Can't quite shape yourself up right? Show your different sides with a Saleor styles.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Ever have those days where you feel a bit geometric? Can't quite shape yourself up right? Show your different sides with a Saleor styles."@@ -1142,8 +1106,7 @@"product_type": 14,"name": "Polo Shirt","slug": "polo-shirt-2",- "description": "Polo? Yolo… so don’t waste time on the wrong apparel. Choose a polo shirt that looks as good as you feel.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Polo? Yolo… so don’t waste time on the wrong apparel. Choose a polo shirt that looks as good as you feel."@@ -1171,8 +1134,7 @@"product_type": 14,"name": "Polo Shirt","slug": "polo-shirt-3",- "description": "Wondering if this will look as good on you as it does on the screen? The answer is yes. A quality polo with smart styling.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Wondering if this will look as good on you as it does on the screen? The answer is yes. A quality polo with smart styling."@@ -1200,8 +1162,7 @@"product_type": 14,"name": "Polo Shirt","slug": "polo-shirt-4",- "description": "They say polo is the sport of kings. Or was that stamp collecting? Either way, this shirt is fit for a king of Saturday night.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "They say polo is the sport of kings. Or was that stamp collecting? Either way, this shirt is fit for a king of Saturday night."@@ -1229,8 +1190,7 @@"product_type": 14,"name": "T-shirt","slug": "t-shirt-2",- "description": "One style fits all. Get a look that works even when you are taking it easy. Relaxed wear for the masses.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "One style fits all. Get a look that works even when you are taking it easy. Relaxed wear for the masses."@@ -1258,8 +1218,7 @@"product_type": 14,"name": "T-shirt","slug": "t-shirt",- "description": "A classic tee for a timeless look, at a great price. Feel like a million bucks without breaking the bank.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "A classic tee for a timeless look, at a great price. Feel like a million bucks without breaking the bank."@@ -1287,8 +1246,7 @@"product_type": 14,"name": "T-shirt","slug": "t-shirt-4",- "description": "Want to look like you just fell out of bed? Sometimes style can be effortless. Throw it on get on with having a good day.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Want to look like you just fell out of bed? Sometimes style can be effortless. Throw it on get on with having a good day."@@ -1316,8 +1274,7 @@"product_type": 14,"name": "T-shirt","slug": "t-shirt-3",- "description": "Your t-shirt is your second skin. It’s the version of you that you show to the world. Wear one that flows with your movements and is built to last.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Your t-shirt is your second skin. It’s the version of you that you show to the world. Wear one that flows with your movements and is built to last."@@ -1345,8 +1302,7 @@"product_type": 14,"name": "Black Hoodie","slug": "black-hoodie",- "description": "Special offer. Buy a hood and get a free jet black sweater attached. Perfect for when you are up to no good.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Special offer. Buy a hood and get a free jet black sweater attached. Perfect for when you are up to no good."@@ -1374,8 +1330,7 @@"product_type": 14,"name": "Blue Hoodie","slug": "blue-hoodie",- "description": "Special offer. Buy a superhero blue sweater and get a free hood attached. Ideal for when you are out saving the world.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Special offer. Buy a superhero blue sweater and get a free hood attached. Ideal for when you are out saving the world."@@ -1403,8 +1358,7 @@"product_type": 14,"name": "Mustard Hoodie","slug": "mustard-hoodie",- "description": "Who dunnit? It was Colonel Mustard, in the dining room, with the lead piping, wearing this hot as mustard hoodie.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Who dunnit? It was Colonel Mustard, in the dining room, with the lead piping, wearing this hot as mustard hoodie."@@ -1432,8 +1386,7 @@"product_type": 14,"name": "White Hoodie","slug": "white-hoodie",- "description": "Get your slouch on and be seen with a whiter than white hoodie straight from the streets. Relaxed stylin’ and profilin’ with flair.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Get your slouch on and be seen with a whiter than white hoodie straight from the streets. Relaxed stylin’ and profilin’ with flair."@@ -1458,8 +1411,7 @@"product_type": 15,"name": "Sea Lullabies","slug": "sea-lullabies",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Sea Lullabies by Digital Audio."@@ -1484,8 +1436,7 @@"product_type": 15,"name": "Lake Tunes","slug": "lake-tunes",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Lake Tunes by Digital Audio."@@ -1510,8 +1461,7 @@"product_type": 15,"name": "Ocean Poems","slug": "ocean-poems",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Ocean Poems by Digital Audio."@@ -1536,8 +1486,7 @@"product_type": 15,"name": "Bathroom Songs","slug": "bathroom-songs",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Bathroom Songs by Digital Audio."@@ -1562,8 +1511,7 @@"product_type": 15,"name": "Lagoon Chants","slug": "lagoon-chants",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Lagoon Chants by Digital Audio."@@ -1588,8 +1536,7 @@"product_type": 15,"name": "Waterfall Ballads","slug": "waterfall-ballads",- "description": "",- "description_json": {+ "description": {"blocks": [{"data": {"text": "Waterfall Ballads by Digital Audio."@@ -10348,8 +10295,7 @@"slug": "summer-collection","background_image": "collection-backgrounds/summer_F5A4bVb.jpg","background_image_alt": "",- "description": "The Saleor Summer Collection features a range of products that feel the heat of the market. A demo store for all seasons. Saleor captures the open source, e-commerce sun.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "The Saleor Summer Collection features a range of products that feel the heat of the market. A demo store for all seasons. Saleor captures the open source, e-commerce sun."@@ -10371,8 +10317,7 @@"slug": "winter-sale","background_image": "collection-backgrounds/clothing_R7nkNxS.jpg","background_image_alt": "",- "description": "The Saleor Winter Sale is snowed under with seasonal offers. Unreal products at unreal prices. Literally, they are not real products, but the Saleor demo store is a genuine e-commerce leader.",- "description_json": {+ "description": {"blocks": [{"data": {"text": "The Saleor Winter Sale is snowed under with seasonal offers. Unreal products at unreal prices. Literally, they are not real products, but the Saleor demo store is a genuine e-commerce leader."@@ -10394,8 +10339,7 @@"slug": "featured-products","background_image": "collection-backgrounds/clothing_R7nkNxS.jpg","background_image_alt": "",- "description": "Featured Products. Literally, they are not real products, but the Saleor demo store is a genuine e-commerce leader.",- "description_json": {+ "description": {"blocks": [{"key": "","data": {},diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex f7361414cf..63110ec758 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -12,6 +12,7 @@ import pytestimport pytzfrom django.conf import settingsfrom django.contrib.auth.models import Group, Permission+from django.contrib.postgres.search import SearchVectorfrom django.contrib.sites.models import Sitefrom django.core.files import Filefrom django.core.files.uploadedfile import SimpleUploadedFile@@ -94,6 +95,7 @@ from ..warehouse.models import Allocation, Stock, Warehousefrom ..webhook.event_types import WebhookEventTypefrom ..webhook.models import Webhookfrom ..wishlist.models import Wishlist+from .utils import dummy_editorjsclass CaptureQueriesContext(BaseCaptureQueriesContext):@@ -1572,6 +1574,7 @@ def product_list(product_type, category, warehouse, channel_USD, channel_PLN):pk=1486,name="Test product 1",slug="test-product-a",+ description_plaintext="big blue product",category=category,product_type=product_type,),@@ -1579,6 +1582,7 @@ def product_list(product_type, category, warehouse, channel_USD, channel_PLN):pk=1487,name="Test product 2",slug="test-product-b",+ description_plaintext="big orange product",category=category,product_type=product_type,),@@ -1586,6 +1590,7 @@ def product_list(product_type, category, warehouse, channel_USD, channel_PLN):pk=1489,name="Test product 3",slug="test-product-c",+ description_plaintext="small red",category=category,product_type=product_type,),@@ -2746,7 +2751,7 @@ def collection(db):collection = Collection.objects.create(name="Collection",slug="collection",- description="Test description",+ description=dummy_editorjs("Test description."),)return collection@@ -2756,7 +2761,7 @@ def published_collection(db, channel_USD):collection = Collection.objects.create(name="Collection USD",slug="collection-usd",- description="Test description",+ description=dummy_editorjs("Test description."),)CollectionChannelListing.objects.create(channel=channel_USD,@@ -2772,7 +2777,7 @@ def published_collection_PLN(db, channel_PLN):collection = Collection.objects.create(name="Collection PLN",slug="collection-pln",- description="Test description",+ description=dummy_editorjs("Test description."),)CollectionChannelListing.objects.create(channel=channel_PLN,@@ -2788,7 +2793,7 @@ def unpublished_collection(db, channel_USD):collection = Collection.objects.create(name="Unpublished Collection",slug="unpublished-collection",- description="Test description",+ description=dummy_editorjs("Test description."),)CollectionChannelListing.objects.create(channel=channel_USD, collection=collection, is_published=False@@ -2801,7 +2806,7 @@ def unpublished_collection_PLN(db, channel_PLN):collection = Collection.objects.create(name="Collection",slug="collection",- description="Test description",+ description=dummy_editorjs("Test description."),)CollectionChannelListing.objects.create(channel=channel_PLN, collection=collection, is_published=False@@ -2820,7 +2825,7 @@ def collection_with_image(db, image, media_root, channel_USD):collection = Collection.objects.create(name="Collection",slug="collection",- description="Test description",+ description=dummy_editorjs("Test description."),background_image=image,)CollectionChannelListing.objects.create(@@ -2854,7 +2859,7 @@ def page(db, page_type):data = {"slug": "test-url","title": "Test page",- "content": "test content",+ "content": dummy_editorjs("Test content."),"is_published": True,"page_type": page_type,}@@ -2874,14 +2879,14 @@ def page_list(db, page_type):data_1 = {"slug": "test-url","title": "Test page",- "content": "test content",+ "content": dummy_editorjs("Test content."),"is_published": True,"page_type": page_type,}data_2 = {"slug": "test-url-2","title": "Test page",- "content": "test content",+ "content": dummy_editorjs("Test content."),"is_published": True,"page_type": page_type,}@@ -3018,7 +3023,7 @@ def product_translation_fr(product):language_code="fr",product=product,name="French name",- description="French description",+ description=dummy_editorjs("French description."),)@@ -3035,7 +3040,7 @@ def collection_translation_fr(published_collection):language_code="fr",collection=published_collection,name="French collection name",- description="French description",+ description=dummy_editorjs("French description."),)@@ -3045,7 +3050,7 @@ def category_translation_fr(category):language_code="fr",category=category,name="French category name",- description="French category description",+ description=dummy_editorjs("French category description."),)@@ -3055,7 +3060,7 @@ def page_translation_fr(page):language_code="fr",page=page,title="French page title",- content="French page content",+ content=dummy_editorjs("French page content."),)@@ -3205,7 +3210,9 @@ def description_json():"blocks": [{"key": "",- "data": {},+ "data": {+ "text": "E-commerce for the PWA era",+ },"text": "E-commerce for the PWA era","type": "header-two","depth": 0,@@ -3214,7 +3221,12 @@ def description_json():},{"key": "",- "data": {},+ "data": {+ "text": (+ "A modular, high performance e-commerce storefront "+ "built with GraphQL, Django, and ReactJS."+ )+ },"text": ("A modular, high performance e-commerce storefront ""built with GraphQL, Django, and ReactJS."@@ -3235,7 +3247,17 @@ def description_json():},{"key": "",- "data": {},+ "data": {+ "text": (+ "Saleor is a rapidly-growing open source e-commerce platform "+ "that has served high-volume companies from branches "+ "like publishing and apparel since 2012. Based on Python "+ "and Django, the latest major update introduces a modular "+ "front end with a GraphQL API and storefront and dashboard "+ "written in React to make Saleor a full-functionality "+ "open source e-commerce."+ ),+ },"text": ("Saleor is a rapidly-growing open source e-commerce platform ""that has served high-volume companies from branches "@@ -3252,7 +3274,7 @@ def description_json():},{"key": "",- "data": {},+ "data": {"text": ""},"text": "","type": "unstyled","depth": 0,@@ -3261,7 +3283,9 @@ def description_json():},{"key": "",- "data": {},+ "data": {+ "text": "Get Saleor today!",+ },"text": "Get Saleor today!","type": "unstyled","depth": 0,@@ -3285,7 +3309,9 @@ def other_description_json():"blocks": [{"key": "",- "data": {},+ "data": {+ "text": "A GRAPHQL-FIRST ECOMMERCE PLATFORM FOR PERFECTIONISTS",+ },"text": "A GRAPHQL-FIRST ECOMMERCE PLATFORM FOR PERFECTIONISTS","type": "header-two","depth": 0,@@ -3294,7 +3320,12 @@ def other_description_json():},{"key": "",- "data": {},+ "data": {+ "text": (+ "Saleor is powered by a GraphQL server running on "+ "top of Python 3 and a Django 2 framework."+ ),+ },"text": ("Saleor is powered by a GraphQL server running on ""top of Python 3 and a Django 2 framework."diff --git a/saleor/tests/settings.py b/saleor/tests/settings.pyindex 38a85b8121..ae17de9274 100644--- a/saleor/tests/settings.py+++ b/saleor/tests/settings.py@@ -31,7 +31,6 @@ DEFAULT_CURRENCY = "USD"TIME_ZONE = "America/Chicago"LANGUAGE_CODE = "en"-SEARCH_BACKEND = "saleor.search.backends.postgresql"EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"diff --git a/saleor/tests/utils.py b/saleor/tests/utils.pyindex 792c0dee7a..fd25e64ce3 100644--- a/saleor/tests/utils.py+++ b/saleor/tests/utils.py@@ -1,3 +1,5 @@+import json+from django.db import connections, transaction@@ -12,3 +14,8 @@ def flush_post_commit_hooks():connection.in_atomic_block = Falseconnection.run_and_clear_commit_hooks()connection.in_atomic_block = was_atomic+++def dummy_editorjs(text, json_format=False):+ data = {"blocks": [{"data": {"text": text}, "type": "paragraph"}]}+ return json.dumps(data) if json_format else data