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 2 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# dbt_stripe v0.14.1

fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
## 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.

# 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
3 changes: 1 addition & 2 deletions 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 Expand Up @@ -47,7 +47,6 @@ seeds:
created: timestamp
canceled_at: timestamp
voided_at: timestamp
canceled_at: timestamp
invoice_id: "{{ 'varchar(500)' if target.type in ('redshift','postgres') else 'string'}}"
end: timestamp
balance_transaction_data:
Expand Down
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