Atlas-Authority / marketing-automation

GNU General Public License v3.0
19 stars 16 forks source link

Error: Primary duplicate is accounted for twice: XXXXXXXXXXXX #184

Open apwidejulien opened 2 weeks ago

apwidejulien commented 2 weeks ago

It seems a new "pattern" appeared recently in our marketplace reporting; several entries with same order id (transaction id): image

For the provided example, we have:

This result raise an error in action generation:

Get action for event upgrade , Transaction ID: (AT)IN-EU-000-656-718[AEI-04a806ba-3b02-349e-a8c4-6d6cdc1c93c1]
Found duplicate deals. Pick single deal:  20358085480 , deals to delete: [ '20358085481' ]
Get action for event renewal , Transaction ID: (AT)IN-EU-000-656-718[AEI-04a806ba-3b02-349e-a8c4-6d6cdc1c93c1]
Found duplicate deals. Pick single deal:  20358085480 , deals to delete: [ '20358085481' ]
7/3/2024, 6:14:35 AM ERR! Runner Error:
7/3/2024, 6:14:35 AM ERR! Runner   Error: Primary duplicate is accounted for twice: 20358085480
7/3/2024, 6:14:35 AM ERR! Runner       at ActionGenerator.singleDeal (/usr/src/app/src/lib/deal-generator/actions.ts:210:15)
7/3/2024, 6:14:35 AM ERR! Runner       at ActionGenerator.actionForRenewal (/usr/src/app/src/lib/deal-generator/actions.ts:105:23)
7/3/2024, 6:14:35 AM ERR! Runner       at ActionGenerator.actionsFor (/usr/src/app/src/lib/deal-generator/actions.ts:46:36)
7/3/2024, 6:14:35 AM ERR! Runner       at /usr/src/app/src/lib/deal-generator/actions.ts:39:41
7/3/2024, 6:14:35 AM ERR! Runner       at Array.flatMap (<anonymous>)
7/3/2024, 6:14:35 AM ERR! Runner       at ActionGenerator.generateFrom (/usr/src/app/src/lib/deal-generator/actions.ts:39:19)
7/3/2024, 6:14:35 AM ERR! Runner       at DealGenerator.generateActionsForMatchedGroup (/usr/src/app/src/lib/deal-generator/deal-generator.ts:103:42)
7/3/2024, 6:14:35 AM ERR! Runner       at /usr/src/app/src/lib/deal-generator/deal-generator.ts:46:51
7/3/2024, 6:14:35 AM ERR! Runner       at withAutoClose (/usr/src/app/src/lib/util/helpers.ts:28:12)
7/3/2024, 6:14:35 AM ERR! Runner       at DealGenerator.run (/usr/src/app/src/lib/deal-generator/deal-generator.ts:42:25)

I would be more than happy to help with, but not sure how to deal with this:

Thanks in advance for your help!

boris-moduscreate commented 1 week ago

@nhan-nguyen-se any thoughts on this?

nhan-nguyen-se commented 1 week ago

The questions are about business logic which I have very little with this app. @apwidejulien Do we have a deduplication logic already? If so I think we can extend it to handle more duplication cases we found here.

apwidejulien commented 6 days ago

You probably have more knowledge about business logic with this app than me :smile:

To unblock the import, I ended with this crappy stuff: https://github.com/apwide/marketing-automation/commit/fd1ca73a8d56f10414466751aad73ac5ec84c3cd

If I understood correctly, except for refund, we make a hard assumption that we should have only 1 pair transactionId-licenseId which result in 1 deal into HubSpot. However, with our example, we can see this case can happen. I have the feeling Atlassian recently changed the cardinality of the transactions export to not returning transaction, but transaction lines... (a new column appeared in the mkp export named transactionLineItemId )

What I did was just suffixing the transactionId with transactionLineItemId for the duplicates after having sorted them by maintenance date, so deals should be created for each transactionId, but the problem should probably be fixed in the core to map deal using pair license/txId/txLineId.

boris-moduscreate commented 3 days ago

Hmm ok I think that makes sense @apwidejulien Any chance you can help with the core changes?