Skip to content

Rest API and Magento backend use different validation methods for attribute_code when creating new attributes #33138

@homecoded

Description

@homecoded

Preconditions (*)

  1. Magento 2.4.2
  2. Nothing else needs to be installed

Steps to reproduce (*)

  1. Go to backend
  2. Open Stores -> Attribute -> Product
  3. Click "Add New Attribute"
  4. Enter arbitrary value in "Default Label"
  5. Under "Advanced Attribute Properties" enter an "Attribute Code" that contains an upper case letter, e.g. "Test_Attribute"
  6. Hit save (works!)
  7. Setup Rest-API and send a request to create a product attribute with an attribute code that has uppercase letters, e.g. "Test_Attribute2" (see sample script below)
  8. Check response: "message":"Invalid value of ""%value"" provided for the %fieldName field.","parameters":{"fieldName":"attribute_code","value":"Test_Attribute2"}

Sample bash script for verification (replace baseurl and username/password)

BASE_URL='http://localhost/'
TOKEN=$(curl -X POST "${BASE_URL}index.php/rest/V1/integration/admin/token" \
-H "Content-Type:application/json" \
-d '{"username":"admin", "password":"password123"}')
TOKEN=$(echo $TOKEN | sed "s/\"//g");

curl -X POST "${BASE_URL}index.php/rest/V1/products/attributes" \
-H "authorization: Bearer ${TOKEN}" \
-H 'content-type: application/json' \
-d '{
 "attribute": {
   "attribute_code": "branding_Tester4",
   "default_frontend_label": "Testing",
   "frontend_input": "text"
 }
}'

Expected result (*)

  1. I expect that I can create the same kind of product attributes through backend and Rest-API
  2. I expect that I can use uppercase letters in attribute codes when creating product attributes through backend and frontend.
  3. I expect that backend and rest api work similarly in creating product attributes.

Actual result (*)

  1. I can create product attributes with uppercase letters in attribute_code through backend.
  2. I cannot create product attributes with uppercase letters in attribute_code through Rest API.
  3. Backend and rest api do not work similarly in creating product attributes in regards to attribute_code.-

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Area: APIsComponent: ApiUse with concrete module component label E.g. "Component: Api" + "Catalog"Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressReported on 2.4.2Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

Type

No type

Projects

Status

Pull Request In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions