The wrong code is here:
*/
if (isset(
$this->_data['attribute_code']
) && !\Zend_Validate::is(
$this->_data['attribute_code'],
'StringLength',
['max' => self::ATTRIBUTE_CODE_MAX_LENGTH]
)
) {
throw new LocalizedException(
__('An attribute code must be fewer than %1 characters.', self::ATTRIBUTE_CODE_MAX_LENGTH)
);
}
$defaultValue = $this->getDefaultValue();
$hasDefaultValue = (string)$defaultValue != '';
if ($this->getBackendType() == 'decimal' && $hasDefaultValue) {
$numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL);
$defaultValue = $numberFormatter->parse($defaultValue);
if ($defaultValue === false) {
and here:
if (isset(
$data['attribute_code']
) && !\Zend_Validate::is(
$data['attribute_code'],
'StringLength',
['max' => $attributeCodeMaxLength]
)
) {
throw new LocalizedException(
__('An attribute code must be fewer than %1 characters.', $attributeCodeMaxLength)
);
}
return true;
}
/**
* Add attribute to an entity type
*
* If attribute is system will add to all existing attribute sets
The message An attribute code must be fewer than %1 characters.
is wrong because the length equals to \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH
is acceptable both by the Magento database and by the Zend_Validate_StringLength
validator used:
if ($this->_encoding !== null) {
$length = iconv_strlen($value, $this->_encoding);
} else {
$length = iconv_strlen($value);
}
if ($length < $this->_min) {
$this->_error(self::TOO_SHORT);
}
if (null !== $this->_max && $this->_max < $length) {
$this->_error(self::TOO_LONG);
}
if (count($this->_messages)) {
return false;
} else {
return true;
}
}
}
GitHub issue: 1978