From 37ef9795cc9438d00f0aa677b3cb6eb322b4a683 Mon Sep 17 00:00:00 2001 From: Aleksandar Yalnazov Date: Wed, 30 Sep 2015 12:16:50 +0300 Subject: [PATCH] __getattribute__ now checks for NoneType. --- paymill/models/client.py | 25 +++++++++++++------------ paymill/models/payment.py | 17 +++++++++-------- paymill/models/subscription.py | 12 +++++++----- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/paymill/models/client.py b/paymill/models/client.py index 6b30aef..2e9131d 100644 --- a/paymill/models/client.py +++ b/paymill/models/client.py @@ -34,17 +34,18 @@ class Client(JsonObject): #dynamic JSON to Python representation to resolve circular dependencies between client, payment and subscription def __getattribute__(self, name): attr = object.__getattribute__(self, name) - if name == 'subscription': - from . import subscription - return ListProperty(subscription.Subscription).wrap(attr) - if name == 'payment': - from . import payment - if isinstance(attr, dict): - return ListProperty(payment.Payment).wrap(attr) - if isinstance(attr, str): - return list(payment.Payment(id=attr)) - - return object.__getattribute__(self, name) + if attr is not None: + if name == 'subscription': + from . import subscription + return ListProperty(subscription.Subscription).wrap(attr) + if name == 'payment': + from . import payment + if isinstance(attr, dict): + return ListProperty(payment.Payment).wrap(attr) + if isinstance(attr, str): + return list(payment.Payment(id=attr)) + + return attr def updatable_fields(self): return 'email', 'description' @@ -123,4 +124,4 @@ def by_updated_at(cls, from_date, to_date=None): :param int to_date:the to_date to filter by :return: Filter object """ - return Filter('updated_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL']) \ No newline at end of file + return Filter('updated_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL']) diff --git a/paymill/models/payment.py b/paymill/models/payment.py index d030357..8a743ec 100644 --- a/paymill/models/payment.py +++ b/paymill/models/payment.py @@ -62,14 +62,15 @@ class Payment(JsonObject): #dynamic JSON to Python representation def __getattribute__(self, name): - if name == 'client': - attr = object.__getattribute__(self, name) - if isinstance(attr, str): - return client.Client(id=attr) - if isinstance(attr, dict): - return client.Client(attr) + attr = object.__getattribute__(self, name) + if attr is not None: + if name == 'client': + if isinstance(attr, str): + return client.Client(id=attr) + if isinstance(attr, dict): + return client.Client(attr) - return object.__getattribute__(self, name) + return attr def updatable_fields(self): pass @@ -108,4 +109,4 @@ def by_type(cls, typ='creditcard'): :param str typ: creditcard or debit :return: Filter object """ - return Filter('type', values=(typ,), operator=Filter.OPERATOR['EQUAL']) \ No newline at end of file + return Filter('type', values=(typ,), operator=Filter.OPERATOR['EQUAL']) diff --git a/paymill/models/subscription.py b/paymill/models/subscription.py index 73ce4b5..311231f 100644 --- a/paymill/models/subscription.py +++ b/paymill/models/subscription.py @@ -82,10 +82,12 @@ def updatable_fields(self): #workaround for returned type of amount def __getattribute__(self, name): - if name == 'amount': - attr = object.__getattribute__(self, name) - return int(attr) - return object.__getattribute__(self, name) + attr = object.__getattribute__(self, name) + if attr is not None: + if name == 'amount': + attr = object.__getattribute__(self, name) + return int(attr) + return attr class Order(Order): @classmethod @@ -126,4 +128,4 @@ def by_created_at(cls, from_date, to_date=None): :param int to_date:the to_date to filter by :return: Filter object """ - return Filter('created_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL']) \ No newline at end of file + return Filter('created_at', values=(from_date, to_date), operator=Filter.OPERATOR['INTERVAL'])