No way to set_default or set_override a config with "None"
Bug #1035478 reported by
Vish Ishaya
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
openstack-common |
Fix Released
|
Undecided
|
Vish Ishaya |
Bug Description
if you have a config defined like so
cfg.StrConfig(
there is no way to override it with a None value:
cfg.set_
cfg.set_
cfg.foo == 'bar'
This seems to be because the internal logic for set_default and set_override mean that passing None will clear the existing value.
Changed in openstack-common: | |
status: | New → In Progress |
assignee: | nobody → Vish Ishaya (vishvananda) |
Changed in openstack-common: | |
milestone: | none → 2012.2 |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
Three options for fixing. I'm using set_default in the examples, but it applies to set_override as well.
1) make set_default('foo', None) override the default with the value None and provide a clear_default( 'foo') method to remove it. Internally we store the NoneValue with a special class.
2) provide a NoneValue class that can be used to override the default value with a None, set_default('foo', NoneValue()) will override the internal value. set_default('foo', None) will clear the default as it does today.
3) allow set_default to take a method. When the value is retrieved, the method is lazily evaluated. You could do something like set_default('foo', lambda: None) to override a value with None. set_default('foo', None) will clear the default as it does today. This definitely is interesting but it seems a little complex and Non-obvious
Option 1 changes the existing api very slightly, but it seems more correct. In order to keep compatibility and keep things simple I've implemented 2). Open to suggestions on the review