Skip to content

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

@rcoup

Description

@rcoup

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions