"name" is ignored when creating a new Item Attribute Value through API

I am using frappeclient to handle API calls and I noticed that when I am inserting new Item Attribute Values, item is created correctly, but “name” is ignored.

API call:

client.insert({"doctype": "Item Attribute Value",
                                'attribute_value': "testblabla",
                                'name': "test123",
                                'abbr': "test",
                                'parentfield': 'item_attribute_values',
                                'parenttype': 'Item Attribute',
                                'parent': 'Condition'})

Respone from server:

{'name': '08942f7a68',
 'owner': XXX',
 'creation': '2023-06-02 10:42:11.114369',
 'modified': '2023-06-02 10:42:11.114369',
 'modified_by': 'XXX',
 'docstatus': 0,
 'idx': 0,
 'attribute_value': 'testblabla',
 'abbr': 'test',
 'parent': 'Condition',
 'parentfield': 'item_attribute_values',
 'parenttype': 'Item Attribute',
 'doctype': 'Item Attribute Value'}

Is it a bug or am I doing something wrong? Is there any way to bypass it?

Hi @testrid ,

In Frappe, the name field serves as a unique identifier for each document and follows a specific naming convention based on the document’s doctype. When inserting a new document using the API, if you provide a value for the name field, it will be ignored, and Frappe will automatically generate a unique name for the new document.

If you need to access or reference the newly created Item Attribute Value document later, you can use the name field returned in the response from the server.

In your case, the response from the server shows that the new Item Attribute Value was successfully created with the generated name field set to '08942f7a68'. You can use this name value for any further operations or references related to this document.

Therefore, the behavior you are observing is not a bug, and you do not need to bypass it. You can utilize the generated name value as necessary for your application logic.

Hope this will help you out.

Thank you.


thanks for your reply - unfortunately it hasn’t solved the issue, as I am connecting different data sources together and creating additional dictionaries linking different IDs would create unnecessary boilerplate. But your answer pushed me into the right direction, so I will share my solution for the sake of community and future google results :wink:

Different default doctypes follow different naming conventions. For example, doctype “item”, has by default naming convention “field:item_code”, i.e. name will be the same as field item_code. For whatever reason, naming convention was not set for “Item Attribute Value”, which caused that default mechanism of random id was overwriting received “name” field. It can be changed in doctype settings (for this doctype: HOST/app/doctype/Item%20Attribute%20Value).

In my case the most convenient choice was to simply set abbreviation as a name, but there are also other options.

The best practice would be to raise an error that API received a POST request with an attribute which is not expected, but it is great anyway that ERPNext is so flexible that it was only a quick change to fix the issue.

Best, t.