Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeCode column name length validation throws wrong error message #20766 #20767

Conversation

irajneeshgupta
Copy link
Member

@irajneeshgupta irajneeshgupta commented Jan 29, 2019

#20766

Description (*)

Attribute length 30 char check and error message added.

Fixed Issues (if relevant)

  1. AttributeCode column name length validation throws wrong error message #20766: Issue title:AttributeCode column name length validation throws wrong error message
  2. ...

Manual testing scenarios (*)

  1. ...
  2. ...

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @irajneeshgupta. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@brosenberger
Copy link
Contributor

@irajneeshgupta could you tell me the reason why the attribute code is restricted to 30 chars? would further be an input validation within the backend form be useful?

@irajneeshgupta
Copy link
Member Author

irajneeshgupta commented Jan 29, 2019

@irajneeshgupta could you tell me the reason why the attribute code is restricted to 30 chars? would further be an input validation within the backend form be useful?

yes , input validation max-30 will be useful , i think 30 chars are sufficient for attribute_code.

I will update my commit.

Thanks @brosenberger

@brosenberger
Copy link
Contributor

@irajneeshgupta in my case 30 characters are not enough as i am a bit bound by external system constraints for a customer project :-(

@irajneeshgupta
Copy link
Member Author

@irajneeshgupta in my case 30 characters are not enough as i am a bit bound by external system constraints for a customer project :-(

https://magento.stackexchange.com/questions/7491/why-do-attribute-codes-have-a-maximum-length
please read Alan Storm comment in this thread.

@brosenberger
Copy link
Contributor

@irajneeshgupta according to that comment all oracle versions equals and below 12.1 are effected - but neither version of oracle is officially supported by magento 2.3: https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements-tech.html#database
oracle 12.1 is not supported anymore: https://en.wikipedia.org/wiki/Oracle_Database#Releases_and_versions

though there is a constraint on mysql column name lengths of 64 characters (https://dev.mysql.com/doc/refman/8.0/en/identifiers.html) which should be used instead

a comment within the code why X characters are allowed would be nice in every case

@orlangur orlangur self-assigned this Jan 29, 2019
@@ -203,7 +203,8 @@ public function execute()
$this->messageManager->addErrorMessage(
__(
'Attribute code "%1" is invalid. Please use only letters (a-z or A-Z), ' .
'numbers (0-9) or underscore(_) in this field, first character should be a letter.',
'numbers (0-9) or underscore(_) in this field, first character should be a letter, ' .
'and length should be less than 30 characters.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a separate check for length which appears earlier than this.

Also, 30 chars seems to be allowed from regexp.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlangur sir
sure i am adding it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlangur sir ,
i have added seperate length check before string validation.

 $validatorAttrCode = new \Zend_Validate_Regex(
                    ['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,30}$/u']
                );

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlangur
sir, please review the changes.
Thank you.

@milindsingh
Copy link
Member

@orlangur Hi, I too issue some time due to the length limit of attribute_code (i.e 30 chars). Can it be increased?

could you tell me the reason why the attribute code is restricted to 30 chars?

@orlangur
Copy link
Contributor

@milindsingh, nope, there could be a lot of stuff tied to it.

30 chars are sufficient for attribute_code

@brosenberger
Copy link
Contributor

@orlangur any comments to my follow up links why 30 characters are not a hard constraint because of the old oracle version and reference to magento 1.6?

@orlangur
Copy link
Contributor

@brosenberger thanks for pointing out, I found that I already talked on this with Olexii in #10225 (comment). Looks like this one is just a legacy check in Catalog module not in sync with others, I'll check soon and give exact direction to PR author.

@irajneeshgupta
Copy link
Member Author

@orlangur sir,

In this PR that you referenced #10225 \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH
was changed from 255 to 60.

Should i change the string validation to 60 chars. since it is currently checking for 30 chars.
['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,30}$/u']

@irajneeshgupta
Copy link
Member Author

@orlangur sir,
Please review.
Thanks

@@ -210,7 +212,7 @@ public function execute()
}
if (strlen($attributeCode) > 0) {
$validatorAttrCode = new \Zend_Validate_Regex(
['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,30}$/u']
['pattern' => '/^[a-zA-Z\x{600}-\x{6FF}][a-zA-Z\x{600}-\x{6FF}_0-9]{0,60}$/u']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when using the constant above for checking the length, it should be included here as well for the regexp (to be sure if it changes in future and not have failing this constraint which was already checked previously)

Copy link
Member Author

@irajneeshgupta irajneeshgupta Feb 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brosenberger
you are correct , let me add maxLength i.e, 60 in regex

@sivaschenko
Copy link
Member

Hi @irajneeshgupta can you please check #20526 I believe it resolves the issue. Let's close this pull request as a duplicate and collaborate to deliver #20526

@irajneeshgupta
Copy link
Member Author

@sivaschenko
you are correct.

@ghost
Copy link

ghost commented Feb 14, 2019

Hi @irajneeshgupta, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants