charm and bundle _representation can contain unsupported keys
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
charmworld |
Triaged
|
High
|
Unassigned |
Bug Description
There are several places in the code where data is cast as a Charm or Bundle to normalise the data. eg
bundle_data = Bundle(
There are a few problems with this pattern. The caller knows about the private member. The caller assumes that _representation is sane -- it might contain unsupported keys. The caller can mutate the dict which will change the bundle or charm object.
The __init__ methods of Bundle and Charm could limit the update the _representation to keys that are supported.
A property like @representation or __iter__ could return a copy of the dict to ensure only sane and normalised key-values are returned that cannot mutate the object.
This pattern is common and methods do not now if the dict they are working with is a _representation. We may have code mutating objects and we do not understand the repercussions.