Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove the attribute presentation flags from the ORM (#19694)
Lukasz Ostrowskib2c08482a9d3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 008b85eb7c..fb0310a57c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -47,6 +47,7 @@ All notable, unreleased changes to this project will be documented in this file.To upgrade, grant staff members and apps the permission matching the attribute types they operate on. A requestor holding only `MANAGE_PRODUCTS` can no longer create attribute values.- Removed the deprecated storefront and dashboard presentation flags of attributes: `filterableInStorefront`, `filterableInDashboard`, `availableInGrid` and `storefrontSearchPosition`. Saleor never read them. Every surface exposing them is gone: the fields of the `Attribute` type, the inputs of `AttributeCreateInput` and `AttributeUpdateInput` (which also covers `attributeBulkCreate` and `attributeBulkUpdate`), the `filterableInStorefront`, `availableInGrid` and `filterableInDashboard` inputs of `AttributeFilterInput`, the `filterableInDashboard` input of `AttributeWhereInput`, and the `FILTERABLE_IN_STOREFRONT`, `FILTERABLE_IN_DASHBOARD`, `AVAILABLE_IN_GRID` and `STOREFRONT_SEARCH_POSITION` values of `AttributeSortField`. Keep the logic in the storefront or dashboard, or use `Attribute` metadata instead. The database columns are still present and will be dropped in a later release.+- The default ordering of attributes is now `slug` alone. Previously the `attributes(...)` query (and other places listing attributes without an explicit `sortBy`) returned them ordered by `storefrontSearchPosition` first, settable through `attributeCreate` and `attributeUpdate`. If you relied on that field to control the order of attributes, it is no longer honored; sort them in the storefront or keep the position in `Attribute` metadata instead.- Providing an empty `attributes` list (`null` or `[]`) in `where` filters for pages, products, and product variants now matches no objects instead of being ignored. The same now applies to a no-op attribute filter that builds no condition, such as an empty reference container (`reference: { pageSlugs: {} }`) - previously such a filter matched all product variants.### GraphQL APIdiff --git a/saleor/attribute/migrations/0059_remove_attribute_presentation_flags.py b/saleor/attribute/migrations/0059_remove_attribute_presentation_flags.pynew file mode 100644index 0000000000..fcaf2496ab--- /dev/null+++ b/saleor/attribute/migrations/0059_remove_attribute_presentation_flags.py@@ -0,0 +1,74 @@+from django.db import migrations, models+++class Migration(migrations.Migration):+ """De-register the attribute presentation flags from the ORM.++ The columns stay in the database so pods still running the previous version keep+ working during a rolling deploy. They keep their NOT NULL constraint and gain a+ `db_default`, so the new ORM, which no longer knows them, can insert rows without+ the old pods ever reading a NULL through the deprecated GraphQL fields, which are+ still non-nullable there.++ TODO: drop the columns in 3.25, once no process runs the version that still+ writes them.+ """++ dependencies = [+ ("attribute", "0058_alter_attribute_type"),+ ]++ operations = [+ migrations.AlterModelOptions(+ name="attribute",+ options={"ordering": ("slug",)},+ ),+ migrations.SeparateDatabaseAndState(+ database_operations=[+ migrations.AlterField(+ model_name="attribute",+ name="filterable_in_storefront",+ field=models.BooleanField(+ blank=True, default=False, db_default=False+ ),+ ),+ migrations.AlterField(+ model_name="attribute",+ name="filterable_in_dashboard",+ field=models.BooleanField(+ blank=True, default=False, db_default=False+ ),+ ),+ migrations.AlterField(+ model_name="attribute",+ name="available_in_grid",+ field=models.BooleanField(+ blank=True, default=False, db_default=False+ ),+ ),+ migrations.AlterField(+ model_name="attribute",+ name="storefront_search_position",+ field=models.IntegerField(blank=True, default=0, db_default=0),+ ),+ ],+ state_operations=[+ migrations.RemoveField(+ model_name="attribute",+ name="filterable_in_storefront",+ ),+ migrations.RemoveField(+ model_name="attribute",+ name="filterable_in_dashboard",+ ),+ migrations.RemoveField(+ model_name="attribute",+ name="available_in_grid",+ ),+ migrations.RemoveField(+ model_name="attribute",+ name="storefront_search_position",+ ),+ ],+ ),+ ]diff --git a/saleor/attribute/models/base.py b/saleor/attribute/models/base.pyindex 1fd6747a41..60f7a91710 100644--- a/saleor/attribute/models/base.py+++ b/saleor/attribute/models/base.py@@ -202,23 +202,12 @@ class Attribute(ModelWithMetadata, ModelWithExternalReference):is_variant_only = models.BooleanField(default=False, blank=True)visible_in_storefront = models.BooleanField(default=True, blank=True)- # Presentation flags that Saleor never reads. Their GraphQL API surface was- # removed in 3.24; the fields and their columns are to be dropped too. Dropping- # `storefront_search_position` also changes the default ordering below.- filterable_in_storefront = models.BooleanField(default=False, blank=True)- filterable_in_dashboard = models.BooleanField(default=False, blank=True)-- storefront_search_position = models.IntegerField(default=0, blank=True)- available_in_grid = models.BooleanField(default=False, blank=True)-max_sort_order = models.IntegerField(default=None, null=True, blank=True)objects = AttributeManager()class Meta(ModelWithMetadata.Meta):- # `storefront_search_position` is a leftover of the removed presentation- # flags; ordering falls back to `slug` when the column is dropped.- ordering = ("storefront_search_position", "slug")+ ordering = ("slug",)indexes = [*ModelWithMetadata.Meta.indexes,GinIndex(diff --git a/saleor/attribute/tests/fixtures/attribute.py b/saleor/attribute/tests/fixtures/attribute.pyindex e1862e869f..71bcdbfdf5 100644--- a/saleor/attribute/tests/fixtures/attribute.py+++ b/saleor/attribute/tests/fixtures/attribute.py@@ -18,9 +18,6 @@ def attribute_generator():name="Attr",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.DROPDOWN,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,):attribute, _ = Attribute.objects.get_or_create(external_reference=external_reference,@@ -28,9 +25,6 @@ def attribute_generator():name=name,type=type,input_type=input_type,- filterable_in_storefront=filterable_in_storefront,- filterable_in_dashboard=filterable_in_dashboard,- available_in_grid=available_in_grid,)return attribute@@ -114,9 +108,6 @@ def color_attribute(db, attribute_generator, attribute_values_generator):slug="color",name="Color",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)external_references = ["colorAttributeValue1ExternalReference",@@ -140,9 +131,6 @@ def color_attribute_with_translations(db):slug="color",name="Color",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)value1 = AttributeValue.objects.create(attribute=attribute, name="Red", slug="red")AttributeValue.objects.create(attribute=attribute, name="Blue", slug="blue")@@ -160,9 +148,6 @@ def second_color_attribute_with_translations(db):slug="second-color",name="Second color",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)value1 = AttributeValue.objects.create(attribute=attribute, name="Red", slug="red")AttributeValue.objects.create(attribute=attribute, name="Blue", slug="blue")@@ -180,9 +165,6 @@ def attribute_without_values():slug="dropdown",name="Dropdown",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,visible_in_storefront=True,entity_type=None,)@@ -195,9 +177,6 @@ def multiselect_attribute(db, attribute_generator, attribute_values_generator):name="Multi",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.MULTISELECT,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)slugs = ["choice-1", "choice-2"]names = ["Choice 1", "Choice 2"]@@ -217,9 +196,6 @@ def date_attribute(db):name="Release date",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.DATE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.bulk_create([@@ -246,9 +222,6 @@ def date_time_attribute(db):name="Release date time",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.DATE_TIME,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.bulk_create(@@ -275,9 +248,6 @@ def attribute_choices_for_sorting(db):slug="sorting",name="Sorting",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute, name="Global", slug="summer")AttributeValue.objects.create(attribute=attribute, name="Apex", slug="zet")@@ -292,9 +262,6 @@ def boolean_attribute(db):name="Boolean",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.BOOLEAN,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute,@@ -318,9 +285,6 @@ def rich_text_attribute(db):name="Text",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.RICH_TEXT,- filterable_in_storefront=False,- filterable_in_dashboard=False,- available_in_grid=False,)text = "Rich text attribute content."AttributeValue.objects.create(@@ -339,9 +303,6 @@ def rich_text_attribute_page_type(db):name="Text",type=AttributeType.PAGE_TYPE,input_type=AttributeInputType.RICH_TEXT,- filterable_in_storefront=False,- filterable_in_dashboard=False,- available_in_grid=False,)text = "Rich text attribute content."AttributeValue.objects.create(@@ -378,9 +339,6 @@ def plain_text_attribute(db):name="Plain text",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.PLAIN_TEXT,- filterable_in_storefront=False,- filterable_in_dashboard=False,- available_in_grid=False,)text = "Plain text attribute content."AttributeValue.objects.create(@@ -399,9 +357,6 @@ def plain_text_attribute_page_type(db):name="Plain text",type=AttributeType.PAGE_TYPE,input_type=AttributeInputType.PLAIN_TEXT,- filterable_in_storefront=False,- filterable_in_dashboard=False,- available_in_grid=False,)text = "Plain text attribute content."AttributeValue.objects.create(@@ -419,9 +374,6 @@ def color_attribute_without_values(db): # pylint: disable=W0613slug="color",name="Color",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)@@ -440,9 +392,6 @@ def size_attribute(db, attribute_generator, attribute_values_generator): # pylislug="size",name="Size",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)slugs = ["small", "big"]@@ -462,9 +411,6 @@ def weight_attribute(db):slug="material",name="Material",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute, name="Cotton", slug="cotton")AttributeValue.objects.create(@@ -481,9 +427,6 @@ def numeric_attribute(db):type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.NUMERIC,unit=MeasurementUnits.CM,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute, name="9.5", slug="10_5", numeric=9.5@@ -501,9 +444,6 @@ def numeric_attribute_without_unit(db):name="Count",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.NUMERIC,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute, name="9", slug="9", numeric=9)AttributeValue.objects.create(attribute=attribute, name="15", slug="15", numeric=15)@@ -552,9 +492,6 @@ def swatch_attribute(db):name="t-shirt-color",type=AttributeType.PRODUCT_TYPE,input_type=AttributeInputType.SWATCH,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute, name="Red", slug="red", value="#ff0000"@@ -798,9 +735,6 @@ def size_page_attribute(db):slug="page-size",name="Page size",type=AttributeType.PAGE_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute, name="10", slug="10")AttributeValue.objects.create(attribute=attribute, name="15", slug="15")@@ -813,9 +747,6 @@ def tag_page_attribute(db):slug="tag",name="tag",type=AttributeType.PAGE_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)AttributeValue.objects.create(attribute=attribute, name="About", slug="about")AttributeValue.objects.create(attribute=attribute, name="Help", slug="help")diff --git a/saleor/attribute/tests/model_helpers.py b/saleor/attribute/tests/model_helpers.pyindex 67ad9da248..5b98f41aa7 100644--- a/saleor/attribute/tests/model_helpers.py+++ b/saleor/attribute/tests/model_helpers.py@@ -41,7 +41,7 @@ def get_product_attributes(product: Product):)return Attribute.objects.filter(Exists(product_attributes.filter(attribute_id=OuterRef("id")))- ).order_by("storefront_search_position", "slug")+ ).order_by("slug")def get_product_attribute_values(product: Product, attribute: Attribute):diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.py b/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.pyindex 54c606c155..12851281c3 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.py@@ -25,31 +25,26 @@ def attributes_for_filtering_with_channels(name="Attr1",slug="attr1",value_required=True,- storefront_search_position=4,),Attribute(name="AttrAttr1",slug="attr_attr1",value_required=True,- storefront_search_position=3,),Attribute(name="AttrAttr2",slug="attr_attr2",value_required=True,- storefront_search_position=2,),Attribute(name="Attr2",slug="attr2",value_required=False,- storefront_search_position=5,),Attribute(name="Attr3",slug="attr3",value_required=False,- storefront_search_position=1,),])diff --git a/saleor/graphql/attribute/tests/queries/test_attribute_pagination.py b/saleor/graphql/attribute/tests/queries/test_attribute_pagination.pyindex a6b1a77f05..3f3a6aa1bd 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_pagination.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_pagination.py@@ -24,35 +24,30 @@ def attributes_for_pagination(collection, category, channel_USD):name="Attr1",slug="attr_1",value_required=True,- storefront_search_position=4,type=AttributeType.PRODUCT_TYPE,),Attribute(name="AttrAttr1",slug="attr_attr_1",value_required=True,- storefront_search_position=3,type=AttributeType.PRODUCT_TYPE,),Attribute(name="AttrAttr2",slug="attr_attr_2",value_required=True,- storefront_search_position=2,type=AttributeType.PRODUCT_TYPE,),Attribute(name="Attr2",slug="attr_2",value_required=False,- storefront_search_position=5,type=AttributeType.PRODUCT_TYPE,),Attribute(name="Attr3",slug="attr_3",value_required=False,- storefront_search_position=1,type=AttributeType.PRODUCT_TYPE,),]@@ -190,10 +185,10 @@ def test_attributes_pagination_with_sorting(@pytest.mark.parametrize(("filter_by", "attributes_order"),[- ({"search": "AttrAttr"}, ["AttrAttr2", "AttrAttr1"]),- ({"search": "attr_attr"}, ["AttrAttr2", "AttrAttr1"]),- ({"search": "Attr1"}, ["AttrAttr1", "Attr1"]),- ({"valueRequired": False}, ["Attr3", "Attr2"]),+ ({"search": "AttrAttr"}, ["AttrAttr1", "AttrAttr2"]),+ ({"search": "attr_attr"}, ["AttrAttr1", "AttrAttr2"]),+ ({"search": "Attr1"}, ["Attr1", "AttrAttr1"]),+ ({"valueRequired": False}, ["Attr2", "Attr3"]),],)def test_attributes_pagination_with_filtering(@@ -217,7 +212,7 @@ def test_attributes_pagination_with_filtering_in_collection(staff_api_client, attributes_for_pagination, collection, channel_USD):page_size = 2- attributes_order = ["Attr3", "AttrAttr2"]+ attributes_order = ["Attr1", "Attr2"]collection_id = graphene.Node.to_global_id("Collection", collection.id)filter_by = {"inCollection": collection_id}@@ -239,7 +234,7 @@ def test_attributes_pagination_with_filtering_in_category(staff_api_client, attributes_for_pagination, category, channel_USD):page_size = 2- attributes_order = ["Attr3", "AttrAttr2"]+ attributes_order = ["Attr1", "Attr2"]category_id = graphene.Node.to_global_id("Category", category.id)filter_by = {"inCategory": category_id}diff --git a/saleor/graphql/attribute/tests/queries/test_selected_attribute.py b/saleor/graphql/attribute/tests/queries/test_selected_attribute.pyindex a93672a312..bdd6b6b2a8 100644--- a/saleor/graphql/attribute/tests/queries/test_selected_attribute.py+++ b/saleor/graphql/attribute/tests/queries/test_selected_attribute.py@@ -832,11 +832,8 @@ def test_applies_limit_to_multi_product_references(# givenpage_type = page.page_type- # make sure that our attribute is on first position- page_type.page_attributes.update(storefront_search_position=10)page_type.page_attributes.set([page_type_product_reference_attribute])page_type_product_reference_attribute.input_type = AttributeInputType.REFERENCE- page_type_product_reference_attribute.storefront_search_position = 1page_type_product_reference_attribute.save()first_reference = AttributeValue.objects.create(@@ -950,10 +947,7 @@ def test_applies_limit_to_multi_variant_references(# givenpage_type = page.page_type- # make sure that our attribute is on first position- page_type.page_attributes.update(storefront_search_position=10)page_type.page_attributes.set([page_type_variant_reference_attribute])- page_type_variant_reference_attribute.storefront_search_position = 1page_type_variant_reference_attribute.input_type = AttributeInputType.REFERENCEpage_type_variant_reference_attribute.save()@@ -1068,11 +1062,8 @@ def test_applies_limit_to_multi_category_references(# givenpage_type = page.page_type- # make sure that our attribute is on first position- page_type.page_attributes.update(storefront_search_position=10)page_type.page_attributes.set([page_type_category_reference_attribute])page_type_category_reference_attribute.input_type = AttributeInputType.REFERENCE- page_type_category_reference_attribute.storefront_search_position = 1page_type_category_reference_attribute.save()first_reference = AttributeValue.objects.create(@@ -1190,11 +1181,8 @@ def test_applies_limit_to_multi_collection_references():# givenpage_type = page.page_type- # make sure that our attribute is on first position- page_type.page_attributes.update(storefront_search_position=10)page_type.page_attributes.set([page_type_collection_reference_attribute])page_type_collection_reference_attribute.input_type = AttributeInputType.REFERENCE- page_type_collection_reference_attribute.storefront_search_position = 1page_type_collection_reference_attribute.save()first_reference = AttributeValue.objects.create(diff --git a/saleor/product/tests/fixtures/product_type.py b/saleor/product/tests/fixtures/product_type.pyindex d3f26577a6..2d1044cf25 100644--- a/saleor/product/tests/fixtures/product_type.py+++ b/saleor/product/tests/fixtures/product_type.py@@ -34,9 +34,6 @@ def product_type_generator(slug="color",name="Color",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)attribute_value_generator(@@ -53,9 +50,6 @@ def product_type_generator(slug="size",name="Size",type=AttributeType.PRODUCT_TYPE,- filterable_in_storefront=True,- filterable_in_dashboard=True,- available_in_grid=True,)attribute_value_generator(diff --git a/saleor/static/populatedb_data.json b/saleor/static/populatedb_data.jsonindex daf3365791..e1ed63bbea 100644--- a/saleor/static/populatedb_data.json+++ b/saleor/static/populatedb_data.json@@ -6676,11 +6676,7 @@"unit": null,"value_required": true,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6697,11 +6693,7 @@"unit": null,"value_required": false,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6718,11 +6710,7 @@"unit": null,"value_required": false,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6739,11 +6727,7 @@"unit": null,"value_required": false,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6760,11 +6744,7 @@"unit": null,"value_required": false,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6781,11 +6761,7 @@"unit": null,"value_required": true,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6802,11 +6778,7 @@"unit": null,"value_required": true,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6823,11 +6795,7 @@"unit": null,"value_required": true,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": true,- "filterable_in_dashboard": true,- "storefront_search_position": 0,- "available_in_grid": true+ "visible_in_storefront": true}},{@@ -6844,11 +6812,7 @@"unit": null,"value_required": false,"is_variant_only": false,- "visible_in_storefront": true,- "filterable_in_storefront": false,- "filterable_in_dashboard": false,- "storefront_search_position": 0,- "available_in_grid": false+ "visible_in_storefront": true}},{