Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve "Divide by 0" error in stripe__line_item_enhanced #89

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# dbt_stripe v0.14.1

fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
[PR #89](https://github.com/fivetran/dbt_stripe/pull/89) includes the following updates:

## Bug Fixes
- Addressed a potential `Divide by 0` error in calculating `unit_amount` in the `stripe__line_item_enhanced` model. Now, if the denominator `invoice_line_item.quantity` is 0, `unit_amount` will also be 0.

## Under the Hood
- Expanded the `consistency_line_item_enhanced_count` test to also validate potential changes to `unit_amount` sums.
- Adjusted the `invoice_line_item` seed data to include cases where `quantity` = 0 in order to test the above bug fix.

# dbt_stripe v0.14.0
[PR #82](https://github.com/fivetran/dbt_stripe/pull/82) includes the following updates:

Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2
name: 'stripe'

version: '0.14.0'
version: '0.14.1'
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
stripe:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2

name: 'stripe_integration_tests'
version: '0.14.0'
version: '0.14.1'

profile: 'integration_tests'

Expand Down
3 changes: 2 additions & 1 deletion integration_tests/seeds/invoice_line_item_data.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
id,invoice_id,_fivetran_synced,amount,currency,description,discountable,livemode,period_end,period_start,plan_id,proration,quantity,subscription_id,subscription_item_id,type,unique_id,metadata
ad1111,ab1111,2021-02-18 14:16:37,21,usd,description_here,FALSE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,sg555,TRUE,5,sg888,sdm99,,gg665,{}
ba222,bd665,2021-02-18 14:16:37,65,usd,description_here,TRUE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,sdgf5575,FALSE,4,dfs8645,sdgjk5489,,dsgjnik978,"{""external_id"":""1111111-2222-3333-4444-55555555""}"
ba222,bd665,2021-02-18 14:16:37,65,usd,description_here,TRUE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,sdgf5575,FALSE,4,dfs8645,sdgjk5489,,dsgjnik978,"{""external_id"":""1111111-2222-3333-4444-55555555""}"
ba3333,cde3453,2021-02-18 14:16:37,100,usd,description_here,FALSE,TRUE,2021-02-19 14:16:37,2021-02-18 14:16:37,adsdgf5575,TRUE,0,rebge435,greiot45,,briieugh4939,{}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@

-- this test is to make sure the rows counts are the same between versions
with prod as (
select count(*) as prod_rows
select
count(*) as prod_rows,
sum(unit_amount) as unit_amount
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
from {{ target.schema }}_stripe_prod.stripe__line_item_enhanced
),

dev as (
select count(*) as dev_rows
select
count(*) as dev_rows,
sum(unit_amount) as unit_amount
from {{ target.schema }}_stripe_dev.stripe__line_item_enhanced
)

-- test will return values and fail if the row counts don't match
select *
from prod
join dev
on prod.prod_rows != dev.dev_rows
on prod.prod_rows != dev.dev_rows
or prod.unit_amount != dev.unit_amount
7 changes: 6 additions & 1 deletion models/standardized_models/stripe__line_item_enhanced.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ with invoice_line_item as (
cast(balance_transaction.type as {{ dbt.type_string() }}) as transaction_type,
cast(invoice_line_item.type as {{ dbt.type_string() }}) as billing_type,
cast(invoice_line_item.quantity as {{ dbt.type_numeric() }}) as quantity,
cast((invoice_line_item.amount/invoice_line_item.quantity) as {{ dbt.type_numeric() }}) as unit_amount,

cast(case
when invoice_line_item.quantity = 0 then 0
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
else (invoice_line_item.amount / invoice_line_item.quantity)
end as {{ dbt.type_numeric() }}) as unit_amount,

cast(discount.total_discount_amount as {{ dbt.type_numeric() }}) as discount_amount,
cast(invoice.tax as {{ dbt.type_numeric() }}) as tax_amount,
cast(line_item_aggregate.total_line_item_amount as {{ dbt.type_numeric() }}) as total_line_item_amount,
Expand Down