Skip to content

Fix customer email length validation before save (#40842)#40844

Open
ajith107 wants to merge 2 commits into
magento:2.4-developfrom
ajith107:fix/40842-customer-email-length-validation
Open

Fix customer email length validation before save (#40842)#40844
ajith107 wants to merge 2 commits into
magento:2.4-developfrom
ajith107:fix/40842-customer-email-length-validation

Conversation

@ajith107

@ajith107 ajith107 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add Magento\Customer\Model\Validator\Email to validate customer email length against the 255-character database limit (customer_entity.email).
  • Register the validator in the customer save validation group so validation runs for storefront registration, admin, API, and other save paths.
  • Return a user-friendly "Email" uses too many characters. message instead of a raw NoSuchEntityException that exposes websiteId.

Fixes #40842

Issue

When registering with an email longer than 255 characters, Magento attempted to save to the database and then failed with:

No such entity with email = ..., websiteId = 1

Manual testing

  • Storefront /customer/account/create with 256+ character email shows "Email" uses too many characters.
  • Storefront registration with a valid email succeeds

Automated testing

php vendor/bin/phpunit app/code/Magento/Customer/Test/Unit/Model/Validator/EmailTest.php

Test plan

  • Register a customer with an email of 256+ characters on the storefront; confirm the validation message is shown.
  • Register a customer with a valid email; confirm account creation succeeds.
  • (Optional) Create a customer in Admin with a 256+ character email; confirm the same validation message.

Validate email length against the 255-character database limit during
customer save to return a user-friendly error instead of exposing
websiteId in a NoSuchEntityException.

Fixes magento#40842

Co-authored-by: Cursor <cursoragent@cursor.com>
@m2-assistant

m2-assistant Bot commented Jun 1, 2026

Copy link
Copy Markdown

Hi @ajith107. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jun 1, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Jun 1, 2026
@ajith107

ajith107 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@magento run all tests

Comment thread app/code/Magento/Customer/Model/Validator/Email.php Outdated
Address PR review feedback by reusing the existing Customer module
i18n string that states the 255-character limit.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ajith107

ajith107 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@magento run all tests

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

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: review

Projects

Status: Review in Progress

Development

Successfully merging this pull request may close these issues.

Lack of email length validation exposes the website id during customer creation

3 participants