Closed justinwagg closed 4 months ago
Thanks for the thorough scoping @justinwagg ! At first glance these changes to address your issue make sense to me. Let me sync with my team and confirm that there aren't any intricacies I'm missing. If so we will prioritize this for a coming fix!
Thanks @fivetran-avinash !
Hi @justinwagg , we did our initial assessment and agree with your proposed changes! Our plan is to bring this task into the coming sprint next week and we will prioritize bringing in all the discount codes per order so there are no aggregate issues downstream.
Let us know if you have any questions! We'll be in touch when our solution is live for you to try out.
Hi @justinwagg , we've deployed your suggested changes live in our latest release of dbt_shopify_source
. Upgrade to the newest version of our package in your packages.yml
and you should be good to see all your discount codes! https://hub.getdbt.com/fivetran/shopify_source/latest/
Let me know if you have any additional questions and feel free to submit any other features or bugs that come to mind!
Is there an existing issue for this?
Describe the issue
Summary
The model stg_shopify__order_discount_code results in a table that incorrectly limits the number of included coupon codes per order to 1.
Impact
stg_shopify__order_discount_code
is incorrect. And therefore consumers of this model are too.shopify__orders
transformation.shopify__orders.count_discount_codes_applied
,shopify__orders.shipping_discount_amount
,shopify__orders.percentage_calc_discount_amount
,shopify__orders.fixed_amount_discount_amount
may be incorrect.For example here
Issue
The issue is caused by this line:
https://github.com/fivetran/dbt_shopify_source/blob/738491aef12c2b8faf0ce031ba5f93c3cb1f5381/models/stg_shopify__order_discount_code.sql#L37
This is not a good sanity check. It assumes there will only ever be 1 discount code applied to an order. There is no reason why there can't be multiple discounts per order. See the order resource documentation: https://shopify.dev/docs/api/admin-rest/2024-04/resources/order#resource-object, specifically
discount_codes
which is described asSteps to reproduce
shopify.order_discount_code
and see 2 rows for the order, 1 per applied coupon. This is correct.stg_shopify__order_discount_code_tmp
and see 2 rows for the order, 1 per applied coupon. This is correct.stg_shopify__order_discount_code
and see 1 row for the order (only the first coupon applied, where index = 1) This is incorrect.shopify__orders
for my test ordershopify__orders.count_discount_codes_applied
is 1. This is incorrect.shipping_discount_amount
,percentage_calc_discount_amount
,fixed_amount_discount_amount
may also be incorrect depending on the order in which the coupon was added to the order.Relevant error log or model output
No response
Expected behavior
The model stg_shopify__order_discount_code does not result in a table that limits the number of included coupon codes per order to 1.
dbt Project configurations
n/a
Package versions
What database are you using dbt with?
bigquery
dbt Version
Additional Context
No response
Are you willing to open a PR to help address this issue?