Creating multiple variants fails sometimes with ValidationError: Item Code is mandatory because Item is not automatically numbered

Hi all,

we have a strange symptom when trying to create mutliple variants from an item template. The template exists and already has other variants. The background job is started, but fails with

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 97, in execute_job
    method(**kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/item_variant.py", line 191, in create_multiple_variants
    variant.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 282, in _save
    self.insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 215, in insert
    self.set_new_name()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 375, in set_new_name
    set_new_name(self)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/naming.py", line 38, in set_new_name
    doc.run_method("autoname")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 758, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1027, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1010, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 752, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 49, in autoname
    msgprint(_("Item Code is mandatory because Item is not automatically numbered"), raise_exception=1)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 309, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 284, in _raise_exception
    raise ValidationError(encode(msg))
ValidationError: Item Code is mandatory because Item is not automatically numbered

Interesting is that when the same is tried again, it works and creates the variants.

The version is

ERPNext: v10.1.38 (master)
Frappe Framework: v10.1.36 (master)

Does anyone else have the same issue? Any insights?

1 Like