This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Fix for UpdateFunction #382
Merged
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.
What did you implement:
Calling the
UpdateFunctionendpoint in the ConfigAPI updated the function in thedefaultspace, even if it was called for a different space. This PR fixes it.How did you implement it:
The initial problem is in the UpdateFunction method in
libkvpackage. It's passed aspaceand a*function.Functioninstance. Thespaceis used correctly when checking for the function's existence, but then it uses theSpaceattribute on thefunction.Functioninstance when actually updating the function. TheSpaceattribute has been set to"default"when it was sent through thevalidateFunctionmethod.I was going to just change the line to insert the updated function to use the
spaceargument, but it seems like the different space confusion (spaceargument vsfn.Space) could happen again. Instead, I went up to thehttpapipackage and set thefn.Spacethere. This is similar to how it's done in the registerFunction handler and makes it easier to reason about.The only change in behavior is that the function is now validated first, then checked for existence in the key-value store, rather than the other way around. This is because the
validateFunctionsets the functionSpaceif it isn't already set, and I needed to do that before checking for existence in a given space. I don't think the switch of order matters.The rest of the changes are just around changing the method signature, service interface, and tests for the new
UpdateFunctionmethod signature.How can we verify it:
Start the Event Gateway locally:
go run cmd/event-gateway/main.go -devRegister a function in a space other than "default".
Update the function.
Call GetFunctions to ensure it reflects your update.
Todos:
Is this ready for review?: YES
Is it a breaking change?: NO