braintree / braintree_python

Braintree Python library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
242 stars 115 forks source link

TypeError: Cannot convert None to Decimal #70

Closed jimrrchen closed 6 years ago

jimrrchen commented 8 years ago

Hey,

I'm getting "TypeError: Cannot convert None to Decimal" whenever I tried to fetch some certain transactions. Here are the tracebacks. The transaction looks fine in Braintree dashboard.

----> 1 braintree.Transaction.find("2vx88hy")

/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/braintree/transaction.pyc in find(transaction_id)
    259             transaction = braintree.Transaction.find("my_transaction_id")
    260         """
--> 261         return Configuration.gateway().transaction.find(transaction_id)
    262 
    263 

/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/braintree/transaction_gateway.pyc in find(self, transaction_id)
     38                 raise NotFoundError()
     39             response = self.config.http().get(self.config.base_merchant_path() + "/transactions/" + transaction_id)
---> 40             return Transaction(self.gateway, response["transaction"])
     41         except NotFoundError:
     42             raise NotFoundError("transaction with id " + repr(transaction_id) + " not found")

/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/braintree/transaction.pyc in __init__(self, gateway, attributes)
    526             self.discounts = [Discount(gateway, discount) for discount in self.discounts]
    527         if "status_history" in attributes:
--> 528             self.status_history = [StatusEvent(gateway, status_event) for status_event in self.status_history]
    529         if "subscription" in attributes:
    530             self.subscription_details = SubscriptionDetails(attributes.pop("subscription"))

/production/sweeper/persistent/virtualenv/local/lib/python2.7/site-packages/braintree/status_event.pyc in __init__(self, gateway, attributes)
      6         Resource.__init__(self, gateway, attributes)
      7 
----> 8         self.amount = Decimal(self.amount)

/usr/lib/python2.7/decimal.pyc in __new__(cls, value, context)
    656             return self
    657 
--> 658         raise TypeError("Cannot convert %r to Decimal" % value)
    659 
    660     # @classmethod, but @decorator is not valid Python 2.3 syntax, so

TypeError: Cannot convert None to Decimal
danakatz commented 8 years ago

@jimrrchen Please reach out to Braintree support -- they'll be able to help you debug issues surrounding specific transactions.

antwan commented 6 years ago

This is not related to a specific transaction. All transactions with authorization adjustments or status events fail to get fetched by the API.

Eg :

image

Results :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <dictcomp>
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/braintree/resource_collection.py", line 38, in items
    for item in self.__method(self.__query, batch):
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/braintree/transaction_gateway.py", line 159, in __fetch
    return [Transaction(self.gateway, item) for item in ResourceCollection._extract_as_array(response["credit_card_transactions"], "transaction")]
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/braintree/transaction.py", line 676, in __init__
    self.authorization_adjustments = [AuthorizationAdjustment(authorization_adjustment) for authorization_adjustment in self.authorization_adjustments]
  File "/home/ubuntu/venv/local/lib/python2.7/site-packages/braintree/authorization_adjustment.py", line 8, in __init__
    self.amount = Decimal(self.amount)
  File "/usr/lib/python2.7/decimal.py", line 657, in __new__
    raise TypeError("Cannot convert %r to Decimal" % value)
TypeError: Cannot convert None to Decimal

Please fix the lib to import such transactions. Amount should be None if the API return None.

jaypatel512 commented 6 years ago

Hey @jimrrchen @Antwan86 !

We were able to reproduce this error, and the fix is on its way.

jaypatel512 commented 6 years ago

The fix is released in 3.39.0. Please update to latest version. Thank you for pointing out the issue. 🥂