fix(kuma-cp) create new object from resource descriptor #3114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
It is not an issue with the current code but it's a trap that we can easily fall into.
ResourceDescriptor
has a methodNewObject()
, but in order to call it, it needs to set internalobjectType
andlistType
fields. Those fields are set byInitDescriptor()
method which is only called when the descriptor is put intoResourceRegistry
.The problem is that the
ResourceDescriptor
can also be retrieved from.Descriptor()
method of the object and this copy of an object does not contain initiatedobjectType
andlistType
which results in panic.I moved the retrieving resource type to
NewObject
itself, I don't think we should be able to create an object which requires extra initialization, especially if the object is copied around instead of passing a pointer.The alternative would be to template
resource-gen
withmodel.InitDescriptor
when the descriptor is generated in the code, but I don't like the fact we can create a struct that is not functional.Issues resolved
No issues.
Documentation
Testing
Backwards compatibility