magento2: Magento_Sales module fails to upgrade (email has a wrong format)
Preconditions
- Magento 2.2.3
- PHP 7.1.16
- MariaDB 10.2.9
Steps to reproduce
- composer update 2.2.3 to 2.2.4
- upgrade Magento_Sales data: current version - 2.0.7, required version - 2.0.9
Expected result
- update ok
Actual result
- upgrade logs : Module ‘Magento_Sales’: Upgrading data… We can’t save the address: Email has a wrong format
In which table should I fix emails ? I have email Null values with the following request
SELECT * FROM `sales_order_address` where email is NULL
SELECT * FROM `sales_order_address` where email is null
SELECT * FROM `quote_address` where email is null ORDER BY `created_at` DESC
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 36 (3 by maintainers)
It was related to null entry email in sales_order_address. resolved by
@kamranmalikawan The solution from @gtlt worked for me, but it did not work at first. We are running Magento 2 Commerce and got their support to help me with a solution. Here is what I ended up doing:
and 2. above I had a handful of emails that were not email addresses at all and fixed these up. Having already done @gtlt solution on NULL values, I had already replaced my NULL emails with noemail@foo.com. It should work with a NULL value if all rows are correct, but I can’t be 100% sure. For me having a dummy email is ok.
I ran the following sql to make sure all my NULL values had dummy emails
After the above, everything upgraded and deployed smoothly. In short, just make sure all the data in the email column are valid email addresses. Hope this helps!
For missing email addresses, I’ve combined two approaches above to use the order email address where available and otherwise use a dummy address:
But why do we have this issue while upgrading to 2.2.4. In my case all rows in
sales_order_address
table havenull
value inemail
column. Is theemail
column newly added in the upgrade? Setting dummy email to the record doesn’t seem correct. What is the correct way? @magento-engcom-team@gtlt To check all email fields on special characters or other symbols, i did this. Because I got ‘Invalid email format’ and searched my ass off when i treid to setup:upgrade
I used the update query to update rows with multiple the same issues
SELECT * FROM quote_address WHERE
emailNOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';
SELECT * FROM
sales_order_addressWHERE
emailNOT REGEXP '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$';
UPDATE
quote_addressSET
email= REPLACE(
email, '', '');
UPDATE
sales_order_addressSET
email= REPLACE(
email, '', '');
@magento-engcom-team @engcom-backlog-nazar @gtlt The problem persists in magento 2.2.5, issue appears to be inconsistent code:
In
\Magento\Sales\Setup\UpgradeData::upgrade
method:method
\Magento\Sales\Setup\UpgradeData::fillQuoteAddressIdInSalesOrderAddress
sets thequote_address_id
insales_order_address
; the code saves to the database the entity\Magento\Sales\Model\Order\Address
which in turn relies on\Magento\Sales\Model\Order\Address\Validator::validate
to apply validation by the resource model.It’s
\Magento\Sales\Model\Order\Address\Validator
that enforces the valid email check. However\Magento\Sales\Setup\UpgradeSchema
does NOT change thesales_order_address.quote_address_id
column, it IS STILL nullable.So why is
\Magento\Sales\Setup\UpgradeData::fillQuoteAddressIdInSalesOrderAddress
necessary when the column it affects is still nullable? Is the column not supposed to be nullable under any condition?Magento team please clarify. Thank you.
It appears to happen to people who have migrated from Magento 1. If you open it up as a ticket on the data migration tool repository he will say everything migrated correctly and it is a problem with the upgrade script.
@gtlt solution worked for me too. Just make sure you rm -rf var/cache/* rm -rf var/page_cache/* rm -rf generated/code/* Before running the magento setup:upgrade again
I was affected by this issue too.
Solution from gtlt resolved this issue. But I also agree with @webspeaks, setting a dummy email address should not be the correct solution.