Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to easily deserialise Model objects from cache responses #13

Open
rcoup opened this issue Oct 26, 2016 · 0 comments · May be fixed by #23
Open

Be able to easily deserialise Model objects from cache responses #13

rcoup opened this issue Oct 26, 2016 · 0 comments · May be fixed by #23

Comments

@rcoup
Copy link

rcoup commented Oct 26, 2016

Accessing eg. my_customer.values is a reasonable way of serialising a model object for eg. caching locally in memcache or redis.

But after retrieving from the cache, deserialising could be easier. Objects without nested subtypes are available via chargebee.Card.construct(values). But currently to get a Customer model instance back from a cache result (.values object), you need to jump through hoops:

    my_customer = chargebee.Customer.construct(values,
        # need to pass in the subtypes to be deserialized properly
        # I got these from chargebee/result.py
        sub_types={
            'billing_address' : chargebee.Customer.BillingAddress,
            'contacts' : chargebee.Customer.Contact,
            'payment_method' : chargebee.Customer.PaymentMethod
        }
    )

Simple-ish solution could be to override construct() in models with subtypes, and move the hardcoded stuff from result.py into the model.
More complex would be for .construct() or a metaclass could find the sub-types?

@rcoup rcoup linked a pull request Feb 8, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant