Closed christian-rli closed 4 years ago
"fields": [null]
is not something I would consider valid. But this is debatable.
Semantically this means "There is a field and this field is nothing" which is weird.
Hmm, that makes sense. I tried to fill out a string that has no foreignKey, but preserving all keys of the metadata json structure. This is not possible however.
When "foreignKeys": [{"fields": [], ...
AND
When "reference":{ "fields": null, ...}
there is a TypeError ('NoneType' object is not iterable).
When "foreignKeys": [{"fields": [], ...
AND
When "reference":{ "fields": [], ...}
there is an Exception (Missing reference in foreign key
).
With the option of an existing field in which there is nothing:
When "foreignKeys": [{"fields": [null], ...
AND
When "reference":{ "fields": [null], ...}
there is a key Error: None
(which is just logical, I suppose)
With everything just null:
When "foreignKeys": [{"fields": null, ...
AND
When "reference":{ "fields": null, ...}
there is a TypeError: 'NoneType' object is not iterable
(because a list is expected)
Now the way I found around this is to just leave foreignKeys as an empty list "foreignKeys": []
. However this eliminates a few json keys from the oemetadata string. I think there is an added value to allowing to preserve those keys even with no foreign keys. The question is how big that value is.
I guess it makes logical sense to have an empty list when there are no foreignKeys. However this does not conform to our approach / our recommendation of just putting null
wherever something does not apply. Although, I suppose helper tools could help users steer around this pitfall...
In your opinion @MGlauer , what would a key preserving empty foreignKeys section look like that omi should be able to parse? Or does the concept of an empty nested object not make sense at all?
You are right, there is no solution to this problem - and this is intentional. If a list has length > 0 it means that there must be an object in this list. Therefore, if there is an object in the list of foreign keys, there is a foreign key and a foreign key has required fields - e.g. fields and a target table with columns. I am not sure what a foreign key without columns would be. So, yes, such a structure does not make sense
OK, thanks for elaborating. I can follow that logic.
From this follows then that strings without a foreign key need to be an empty list like so "foreignKeys": []
. Any helper tools should consider this and it should also probably be reflected in the helpful comments section at the bottom of the string. I'll add it to https://github.com/OpenEnergyPlatform/oemetadata/issues/34
Closing this issue and adapting the original string that made me open this issue.
Omi is unable to parse this metadata string. As far as I can tell, the string contains a valid empty foreign key, but omi seems not to think so. Any idea as to why that is @MGlauer ?