TypeError: cannot concatenate 'str' and 'NoneType' objects
sharifyounes opened this issue · 6 comments
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,
raise NotFoundError("subscription with id " + repr(subscription_id) + " not found")
raise NotFoundError("payment method with nonce " + repr(nonce) + " locked, consumed or not found")
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)
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.
Feel free to open a PR if you'd like, otherwise, we'll add it to our backlog.
I believe this is fixed now. Closing.
Oh wait, it has not. Re-opening.
Opened a PR internally for this, once it gets merged in and released, I'll close this issue.
This is fixed in 3.55.0