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

URGENT Crash Fix: Fixed crash caused by Facebook Beta Shopify Connector #119

Merged
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
47 changes: 26 additions & 21 deletions tap_shopify/streams/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,34 @@
# their values are not equal
def canonicalize(transaction_dict, field_name):
field_name_upper = field_name.capitalize()
value_lower = transaction_dict.get('receipt', {}).get(field_name)
value_upper = transaction_dict.get('receipt', {}).get(field_name_upper)
if value_lower and value_upper:
if value_lower == value_upper:
LOGGER.info((
"Transaction (id=%d) contains a receipt "
"that has `%s` and `%s` keys with the same "
"value. Removing the `%s` key."),
# Not all Shopify transactions have receipts. Facebook has been shown
# to push a null receipt through the transaction
receipt = transaction_dict.get('receipt', {})
if receipt:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really the only change in this PR. All the code below this is simply whitespace change from indenting the code under this if receipt check.

value_lower = receipt.get(field_name)
value_upper = receipt.get(field_name_upper)
if value_lower and value_upper:
if value_lower == value_upper:
LOGGER.info((
"Transaction (id=%d) contains a receipt "
"that has `%s` and `%s` keys with the same "
"value. Removing the `%s` key."),
transaction_dict['id'],
field_name,
field_name_upper,
field_name_upper)
transaction_dict['receipt'].pop(field_name_upper)
else:
raise ValueError((
"Found Transaction (id={}) with a receipt that has "
"`{}` and `{}` keys with the different "
"values. Contact Shopify/PayPal support.").format(
transaction_dict['id'],
field_name,
field_name_upper,
field_name_upper)
transaction_dict['receipt'].pop(field_name_upper)
else:
raise ValueError((
"Found Transaction (id={}) with a receipt that has "
"`{}` and `{}` keys with the different "
"values. Contact Shopify/PayPal support.").format(
transaction_dict['id'],
field_name_upper,
field_name))
elif value_upper:
transaction_dict["receipt"][field_name] = transaction_dict['receipt'].pop(field_name_upper)
field_name))
elif value_upper:
# pylint: disable=line-too-long
transaction_dict["receipt"][field_name] = transaction_dict['receipt'].pop(field_name_upper)


class Transactions(Stream):
Expand Down
6 changes: 6 additions & 0 deletions tests/unittests/test_transaction_canonicalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def test_lowercases_if_capital_only_exists(self):
canonicalize(record, "foo")
self.assertEqual(record, expected_record)

def test_null_receipt_record(self):
record = {"receipt": None}
expected_record = {"receipt": None}
canonicalize(record, "foo")
self.assertEqual(record, expected_record)

Comment on lines +25 to +30
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running this code against current master branch will yield a crash. Running it against this PR yields a success.

def test_removes_uppercase_if_both_exist_and_are_equal(self):
record = {"receipt": {"Foo": "bar", "foo": "bar"}, "id": 2}
expected_record = {"receipt": {"foo": "bar"}, "id": 2}
Expand Down