Repository: saleor/saleor
Pull request: Fix attribute value matching during attribute update
I want to merge this change because if we use `productVariantUpdate` mutation and update attribute values our changed values would not change if slug for the name was unchanged (e.g. slug for both "12L" and "12.L" values is "12L").
 It is because `get_or_create` was used and if id and slug matched it returned the instance instead of updating it with the new value.

#10829 
<!-- Please mention all relevant issue numbers. -->

# Impact

* [ ] New migrations
* [ ] New/Updated API fields or mutations
* [ ] Deprecated API fields or mutations
* [ ] Removed API types, fields, or mutations
* [ ] Documentation needs to be updated

# Pull Request Checklist

<!-- Please keep this section. It will make the maintainer's life easier. -->

* [ ] Privileged queries and mutations are guarded by proper permission checks
* [ ] Database queries are optimized and the number of queries is constant
* [ ] Database migration files are up to date
* [ ] The changes are tested
* [ ] GraphQL schema and type definitions are up to date
* [ ] Changes are mentioned in the changelog


Problem statement:
Fix: updating attribute values with similar values
Updating attribute value with similar value e.g: "424l" to "42.4l" does not update the value. 

to reproduce use query:
```
mutation {
  productVariantUpdate(
    id: "UHJvZHVjdFZhcmlhbnQ6MjAz"
    input: { attributes: { id: "QXR0cmlidXRlOjE1", values: ["24l"] } }
  ) {
    errors {
      code
      field
    }
    productVariant {
     id
      attributes {
        attribute {
          id
          name
        }
        values {
          id
          name
          slug
          value
        }
      }
    }
  }

```
Then change `24l` to `2.4l` or `24L` - this should create new value with those names and new unique slug. But at the moment it returns the old object without updating anything. 

This reproduces in Saleor 3.1+

Hints from issue discussion:
@jakubkuc Please provide more steps to reproduce, at least Saleor version and example mutation/query that causes the issue.

Commit message: change function in pre_save_values from get_or_create to update_or_create

Patch to review:
diff --git a/saleor/graphql/attribute/utils.py b/saleor/graphql/attribute/utils.py
index 4a2ad0d0eae..3fcc60641d0 100644
--- a/saleor/graphql/attribute/utils.py
+++ b/saleor/graphql/attribute/utils.py
@@ -143,14 +143,14 @@ def _resolve_attribute_global_id(cls, error_class, global_id: str) -> int:
     def _pre_save_values(
         cls, attribute: attribute_models.Attribute, attr_values: AttrValuesInput
     ):
-        """Lazy-retrieve or create the database objects from the supplied raw values."""
-        get_or_create = attribute.values.get_or_create
+        """Lazy-update or create the database objects from the supplied raw values."""
+        update_or_create = attribute.values.update_or_create
 
         if not attr_values.values:
             return tuple()
 
         return tuple(
-            get_or_create(
+            update_or_create(
                 attribute=attribute,
                 slug=slugify(value, allow_unicode=True),
                 defaults={"name": value},


Code review comments:
diff_hunk: @@ -143,14 +143,14 @@ def _resolve_attribute_global_id(cls, error_class, global_id: str) -> int:
     def _pre_save_values(
         cls, attribute: attribute_models.Attribute, attr_values: AttrValuesInput
     ):
-        """Lazy-retrieve or create the database objects from the supplied raw values."""
-        get_or_create = attribute.values.get_or_create
+        """Lazy-update or create the database objects from the supplied raw values."""
+        update_or_create = attribute.values.update_or_create
 
         if not attr_values.values:
             return tuple()
 
         return tuple(
-            get_or_create(
+            update_or_create(
path: saleor/graphql/attribute/utils.py
text: @user2:
Shouldn't we use `_update_or_create_value` here? I see it has some differences regarding the slug generation, compared to `_pre_save_values`, cc @user1?

@user1:
We cannot update the attribute value for attributes with choices, so any of these solutions is incorrect.