magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

order increment id collision #33457

Open ioweb-gr opened 3 years ago

ioweb-gr commented 3 years ago

The way the increment id is implemented, it has the potential of colliding. Currently the increment id has a prefix of the store id of the order e.g.

for store id = 5 we have an increment id of 5-----------X for store id = 1 we have an increment id of 1-----------X for store_id = 10 we have an increment id of 10----------X

The potential to collide comes if you generate orders in store 1 to fill up all the available digits after the prefix. When the sequence increases it will collide with the store_id 10s increment id.

This can occur no matter how many digits you have on the increment id for cases like 2 with 20 3 with 30 4 with 40 etc etc etc

The number of orders to actually make them collide is huge to replicate it however it can occur. Actually we had an instance from a migrated website where this exact issue occured because the previous magento version in the orders, it had one less padding 0 on the increment id. So it caused a collision on the first order.

Preconditions (*)

  1. Magento 2.4.1
  2. 10 stores

Steps to reproduce (*)

  1. Create 10 stores on the website so that you have one store with = 1 and one store with id = 10
  2. Fill up orders in the store_id 1 until the 0 digits fill up to reach one extra digit

Expected result (*)

  1. No order has the same increment id as another order.

Actual result (*)

  1. Collision image

The problem has a really easy logical solution, adding a symbol separator to the store id prefix

e.g. from

1000002300 -> 10-00002300 1000002300 -> 1-000002300

This is actually a serious issue in migrated websites when syncronizing with 3rd party systems like ERPs and also for coherence on the system. When searching past orders it can give the wrong data.


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 3 years ago

Hi @ioweb-gr. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

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

Please, add a comment to assign the issue: @magento I am working on this


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

victortodoran commented 3 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 3 years ago

Hi @victortodoran. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 3 years ago

Hi @victortodoran, here is your Magento Instance: https://cfb78538b62dfd19735be4d64c74c70e-2-4-develop.instances.magento-community.engineering Admin access: https://cfb78538b62dfd19735be4d64c74c70e-2-4-develop.instances.magento-community.engineering/admin_12d4 Login: 96086e41 Password: 56deba2c3780

m2-assistant[bot] commented 3 years ago

Hi @engcom-Delta. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Delta commented 3 years ago

Hi @ioweb-gr , I tried with 3 stores on Magento 2.4.2 ,unfortunately I could not find this issue reproducible. found that order numbers are generated like Store1--> 1000000001,1000000002,1000000003..etc Store 2--> 2000000001,2000000002,2000000003..etc Store 3 --> 3000000001,3000000002,3000000003..etc.

Hence, added the lable 'Needs update'.

Thanks

ioweb-gr commented 3 years ago

Hi you didn't read the description correctly. You need to either have migrated data from M1 which used one less digit than M2 or you need to fill all the order sequence numbers for store 1. Finally you need 10 stores

The collission comes when the first shop fills all available digits with orders and adds an extra digit. For example for store with Id 1 and sequence 1000000001

When you place order 1999999999

the next in queue is 10000000001

and this number is now in the sequence of store Id 10's first order

engcom-Delta commented 3 years ago

Hi @ioweb-gr , We can not place those many orders to verify this issue .Hence request to provide your inputs for further action on this ticket.

Thanks

ioweb-gr commented 3 years ago

@engcom-Delta Indeed I know it's not realistic that someone will place so many orders to reproduce the issue in a sample instance as it would require filling up all the numbers. However the issue will become apparent if you create a few orders in store id = 1 and store = 10 on Magento 1 then migrate. The first order will cause a collision.

The only sensible way to reproduce this issue is to

  1. Create 10 stores so that you have a store with id = 1 and store with id = 10
  2. Increase the increment id sequence number in the database for store_id = 1 to cover all the available digits
  3. Place an order in store_id = 1 (this order will become a duplicate)

However I do think that you don't even have to place that many orders on the website to replicate. It's alogical flaw that you can verify in an excel file by adding the sequence numbers.

engcom-Delta commented 3 years ago

Hi @ioweb-gr , Thanks for confirming , we tried to understand logical flaw in this . Hence adding label feature request.

Regards,

ioweb-gr commented 3 years ago

Sure sounds great. As long as the issue is confirmed. Although I think it's a bug not a new feature. Increment ids should be unique per order and having a collission is a problem.

github-jira-sync-bot commented 3 years ago

Unfortunately, not enough information was provided to create a Jira ticket. Please make sure you added the following label(s): Reproduced on 2.4.x, ^Area:.*

Once all required labels are present, please add Issue: Confirmed label again.

github-jira-sync-bot commented 3 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-1292 is successfully created for this GitHub issue.

m2-assistant[bot] commented 3 years ago

:white_check_mark: Confirmed by @engcom-Delta. Thank you for verifying the issue.
Issue Available: @engcom-Delta, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] commented 2 years ago

Hi @engcom-Lima. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Lima commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Lima. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Lima, here is your Magento Instance: https://560743bdad84aa2c111957670d6008ed.instances.magento-community.engineering Admin access: https://560743bdad84aa2c111957670d6008ed.instances.magento-community.engineering/admin_014c Login: 3c503984 Password: 828cb5146e98

engcom-Lima commented 2 years ago

Hi @ioweb-gr i have tried to reproduce the issue. I have used performance fixtures in which around 50k orders got created with 10 store views. Here, didn't found any increment_id which got duplicated.Please refer this video for your reference.

ioweb-gr commented 2 years ago

Hi @ioweb-gr i have tried to reproduce the issue. I have used performance fixtures in which around 50k orders got created with 10 store views. Here, didn't found any increment_id which got duplicated.Please refer this video for your reference.

Hi @engcom-Lima Please read comment https://github.com/magento/magento2/issues/33457#issuecomment-910233368

You need to place enough orders on store id = 1 to fill all available increment digits in order to make it shift and add one extra digit. 50k orders is too little to cover all available digits.

To sum it up, I noticed the issue exists because M1 used one less digit, so after migration, this collision became apparent.

Put the numbers in an excel file and start filling up the digits in one column and add the store id = 10 increment ids in the second column. You'll notice the collision.

engcom-Lima commented 2 years ago

:heavy_check_mark: Issue confirmed

Issue got reproduced in 2.4-develop branch.

Description: Order ids getting duplicated while creating orders from different stores.

Pre-requisite:

  1. Magento should be up and running.
  2. Multiple stores should be created.
  3. Product should be created.

Steps to reproduce:

  1. Set the order increment by running below MySql query: ALTER TABLE sequence_order_1 AUTO_INCREMENT=1999999999;
  2. Go to frontend && place orders from store 1.
  3. Also,place an order from store 2.
  4. Go admin panel and in sales >> orders.
  5. Check the order ids in the grids.

Expected result: Order id should not get duplicated. Actual result: Order id got duplicated.

Screenshot: Screenshot from 2022-07-06 12-54-21 Hence,confirming the issue.

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-5912 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

:white_check_mark: Confirmed by @engcom-Lima. Thank you for verifying the issue.
Issue Available: @engcom-Lima, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

ioweb-gr commented 2 years ago

Thanks for confirming the issue. Up until now there is no way to work around this, only with third party modules which will alter the sequences but they are all slow and prone to other errors including more collisions.

The easiest way to fix this would be to introduce the store id as a prefix with a separator character instead of a plain number