Skip to content

Commit

Permalink
fix when certain events have a different schema under the invoice lin…
Browse files Browse the repository at this point in the history
…es (#15)
  • Loading branch information
dmosorast authored and KAllan357 committed Dec 18, 2018
1 parent a60a61b commit 8ba3f65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion tap_stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import stripe
import stripe.error
from stripe.stripe_object import StripeObject
import singer
from singer import utils, Transformer, metrics
from singer import metadata
Expand Down Expand Up @@ -288,7 +289,15 @@ def reduce_foreign_keys(rec, stream_name):
elif stream_name == 'subscriptions':
rec['items'] = [i['id'] for i in rec.get('items', [])] or None
elif stream_name == 'invoices':
rec['lines'] = [l['id'] for l in rec.get('lines', [])] or None
lines = rec.get('lines')
if isinstance(lines, list):
rec['lines'] = [l['id'] for l in rec.get('lines', [])] or None
# Sometimes the lines key is a dict with a list of objects. This behavior may
# manifest for events of type 'invoice.payment_succeeded'
elif isinstance(lines, dict):
for k, val in lines.items():
if isinstance(val, list) and val and isinstance(val[0], StripeObject):
rec['lines'][k] = [li.to_dict_recursive() for li in val]
return rec

def sync_stream(stream_name):
Expand Down
6 changes: 4 additions & 2 deletions tap_stripe/schemas/invoices.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,16 @@
"lines": {
"type": [
"null",
"array"
"array",
"object"
],
"items": {
"type": [
"null",
"string"
]
}
},
"properties": {}
},
"forgiven": {
"type": [
Expand Down

0 comments on commit 8ba3f65

Please sign in to comment.