New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix #2418] Allow function event definitions to be variables #2434
Conversation
Ready for review |
Thanks for submitting this. Looked over the PR and I think we should implement this differently. Basically validation that the config is fine should happen after variables get populated. Otherwise we'll keep adding special cases for things like this. @eahefnawy @pmuens how about we change the service to have a load and a validate command, so loading really only loads variables, then we run through the populate variables command in the Serverless class and afterwards we call validation on the service? |
That's a great idea. |
I gave it a go this morning. The code change was relatively simple and it all seems to work well. |
ok, I found what the problem was. 2 things to note however:
What do you think? |
@flomotlik What's the review process for pull requests? I found the pull request pipeline for this project, but for some reason this pull request seems to be the only one missing from the list. Have I missed anything? |
@flomotlik @eahefnawy @pmuens any chance to get this one looked at soon so I don't have to resolve conflicts every few days? Thanks! |
Also keen on this getting merged in. Having to create a |
I ran into this while looking into an issue I submitted (Issue #2997 ). In its current form this will still error out if you attempt to use ${file(filename)} at the functions: level. Looking through most of the "load" function, a lot of it is setting default values or validating values. If the goal is truly to have everything evaluated after all of the variables are resolved, I almost wonder if mostly everything in the load function of Service.js should move over to the validate. If I have some time later I'll play around with that and see if that still works. |
@flomotlik @eahefnawy @pmuens where are we at with this? It's been over 2 months since the original PR... Anything you need me to change? |
tried this, and it solved the problem for me. thank you @fruffin |
@flomotlik @eahefnawy @pmuens I would really love to get some feedback on this so it can get merged/fixed. I've been using this version for my projects for the last 3 months, but it's a bit annoying to have to merge the latest "released" changes to this temporary version all the time so my projects can keep going forward. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fruffin really sorry this slipped out of my attention 😞 ... imo supporting your use case as laid in the issue is more important than validating the events is an Array type. Even better is how you handled it.
It's working great on my machine too, so this is G2M 😊 ... Will be included in the next release 🙌
Fix broken unit test after merging #2434
Thanks @eahefnawy ! |
I'm curious... With validation happening after variable population, will this mean that I can now define my actual function in an external functionFoo.yml file and reference it with a ${file(functionFoo. yml)} in the function section of my serverless. yml, similar to how we can reference external resources? Ive been trying to make this work for a while now and it seemed like the order of validation - > population needed to be swapped for it to work properly. |
@nfurfaro interesting idea! Do you mean that the order of validation / populations should be swapped after this PR was merged? |
@pmuens this PR is essentially swapping this already. The validation was happening too early causing the external file reference to be validated before it was "expanded". What Nick is referring to is one level higher than the issue I initially raised, but I think the issue is the same |
@fruffin thanks for the clarification! 👍 |
Big thanks for adding this switch. Finally can update to the latests. |
What did you implement:
_Implementing Issue:_ #2418
We used to be able to specify a "file variable" for function event configuration, which was quite useful for a service with multiple handlers. This allowed each handler to be in their own directory, along with the event configuration. This looked something like this:
The
config.yml
file would contain a valid event configuration.Recently, an additional check was added to make sure event configurations are arrays, and it is no longer possible to use variables for event configurations and instead the following error is thrown:
Events for "users" must be an array, not an string
This pull request addresses this issue to restore functionality
How did you implement it:
I have moved the service validation code from the
load
function to a newvalidate
function in the service class, which now gets called from theserverless
class once the variables have been populated.This can later be extended to support more thorough validation of the service.
How can we verify it:
Given a new serverless service with 2 handlers:
posts
andusers
, theserverless.yml
file could look like this:And the
posts
config.yml
file could look like this:I have added unit tests to verify this and have also tested it successfully on one of my projects
Todos:
_Is this ready for review?:_ YES