recurly/recurly-client-python — Issue #12: subscription.attributes lists nonexistant plan_code
Author: jordanorelli
Created: 2011-11-16 19:33:17+00:00
State: open

the .attributes property for subscription objects includes attributes that don't actually exist on the object. I've seen this in other objects, too, so I don't think it's specific to that model.

For example, 'plan_code' is listed in the subscription model's "attributes" list, but a subscription object has no 'plan_code' attribute.

Therefore, the following fails:

account = recurly.Account.get('some_email@example.com')
subscriptions = account.subscriptions()
sub = subscriptions[0]
'plan_code' in sub.attributes # returns true
sub.plan_code # throws attribute error

However, the plan_code *is* available for this object by the following mechanism:

`sub.plan.plan_code`

A break in the attributes list means that you can't really do anything dynamic with the attributes list, like create a dictionary with the object:

`dict((attrib, getattr(sub, attrib)) for attrib in sub.attributes)`

As a result, it's impossible to create a general mechanism for transforming a Recurly object. With the dictionary example, it means that it's impossible to create a mechanism to render arbitrary Recurly objects in a web page; you would have to write a custom render function for every class exposed by the API if you wanted to do that.

The attributes list appears to be used erroneously by the client library itself. For example, the .to_element method generates an xml.etree.ElementTree.Element object, but fails silently at generating elements for the attributes in the attribute list that do not really exist. As a result, if you use .to_element on a subscription object, the Element instance that is returned is not representative of what the API returns. WIth the example of subscriptions, the resulting .to_element Element contains no reference back to the Subscription Plan that the user has subscribed to:

In [10]: e = sub.to_element()

In [11]: list(e)
Out[11]:
[,
,
,
,
,
,
,
,
,
,
,
,
,
,
]