braintree / braintree_python

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

TypeError: cannot concatenate 'str' and 'NoneType' objects #109

Closed sharifyounes closed 5 years ago

sharifyounes commented 5 years ago

When I do subscription.find(user.subscription_id), I get this error if user.subscription_id==None. I can of course change my code to:

if user.subscription_id:
    subscription.find(user.subscription_id)

so no real issue here :)

The "offending" code is here: https://github.com/braintree/braintree_python/blob/master/braintree/subscription_gateway.py#L38

And there's possibly a similar issue here (though it might be wise not to repr(nonce), I'm not sure): https://github.com/braintree/braintree_python/blob/master/braintree/credit_card_gateway.py#L58

Suggesting those should be, respectively,

Tests:

For test_subscription.py:

    @raises(NotFoundError)
    def test_finding_none_raises_not_found_exception(self):
        Subscription.find(None)

For test_credit_card.py:

    @raises(NotFoundError)
    def test_from_nonce_as_none_raises_not_found_exception(self):
        CreditCard.from_nonce(None)
crookedneighbor commented 5 years ago

I looked through the other server side sdks, and most of them do implement checks around the id existing, so we do that here too. Thanks for the report.

crookedneighbor commented 5 years ago

Feel free to open a PR if you'd like, otherwise, we'll add it to our backlog.

crookedneighbor commented 5 years ago

I believe this is fixed now. Closing.

crookedneighbor commented 5 years ago

Oh wait, it has not. Re-opening.

crookedneighbor commented 5 years ago

Opened a PR internally for this, once it gets merged in and released, I'll close this issue.

crookedneighbor commented 5 years ago

This is fixed in 3.55.0