Relations with nil status can be imported #24

Merged
merged 1 commit into from Sep 13, 2017

Conversation

Projects
None yet
2 participants
Owner

wallyworld commented Sep 13, 2017

Some relations don't have status. The nil value was being exported, and the import would complain.
Fix both issues - don't export nil status, and allow import to handle missing status.

QA: migrate a model with a relation without status.

relation.go
@@ -137,6 +137,11 @@ var relationDeserializationFuncs = map[int]relationDeserializationFunc{
func newRelationImporter(v int, checker schema.Checker) func(map[string]interface{}) (*relation, error) {
return func(source map[string]interface{}) (*relation, error) {
+ // Some relations don't have status; remove any nil value
+ // so schema validation doesn't complain.
@howbazaar

howbazaar Sep 13, 2017

Owner

Probably worth leaving a comment about potential import issues due to released bad code.

relation.go
@@ -160,7 +165,11 @@ func relationV1Fields() (schema.Fields, schema.Defaults) {
func relationV2Fields() (schema.Fields, schema.Defaults) {
fields, defaults := relationV1Fields()
fields["status"] = schema.StringMap(schema.Any())
- return fields, defaults
+ v2Defaults := schema.Defaults{"status": schema.Omit}
@howbazaar

howbazaar Sep 13, 2017

Owner

Just do:

defaults["status"] = schema.Omit
relation.go
fields["status"] = schema.StringMap(schema.Any())
- return fields, defaults
+ v2Defaults := schema.Defaults{"status": schema.Omit}
@howbazaar

howbazaar Sep 13, 2017

Owner

you could just call these "defaults"

@wallyworld wallyworld merged commit 7e21278 into juju:master Sep 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment