{"action":"created","issue":{"url":"https://api.github.com/repos/serverless/serverless/issues/2081","repository_url":"https://api.github.com/repos/serverless/serverless","labels_url":"https://api.github.com/repos/serverless/serverless/issues/2081/labels{/name}","comments_url":"https://api.github.com/repos/serverless/serverless/issues/2081/comments","events_url":"https://api.github.com/repos/serverless/serverless/issues/2081/events","html_url":"https://github.com/serverless/serverless/issues/2081","id":176138829,"number":2081,"title":"Self referenced variables don't allow for fallback","user":{"login":"andymac4182","id":1297073,"avatar_url":"https://avatars.githubusercontent.com/u/1297073?v=3","gravatar_id":"","url":"https://api.github.com/users/andymac4182","html_url":"https://github.com/andymac4182","followers_url":"https://api.github.com/users/andymac4182/followers","following_url":"https://api.github.com/users/andymac4182/following{/other_user}","gists_url":"https://api.github.com/users/andymac4182/gists{/gist_id}","starred_url":"https://api.github.com/users/andymac4182/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andymac4182/subscriptions","organizations_url":"https://api.github.com/users/andymac4182/orgs","repos_url":"https://api.github.com/users/andymac4182/repos","events_url":"https://api.github.com/users/andymac4182/events{/privacy}","received_events_url":"https://api.github.com/users/andymac4182/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-09T23:50:41Z","updated_at":"2016-09-15T15:21:13Z","closed_at":null,"body":"# This is a Bug Report\r\n\r\n## Description\r\n\r\nFor bug reports:\r\n* What went wrong? \r\n\r\nWhen referencing a `self:` variable the `getDeepValue` function returns an empty object that means it doesn't fallback to the other option. \r\n* What did you expect should have happened?\r\n\r\nIt load the fallback value\r\n* What was the config you used?\r\n```\r\ndefault:\r\n  CorsOrigins: \r\n    - 'http://test.com'\r\ncurrentVars:\r\n  CorsOrigins: ${self:custom.${self:custom.currentStage}.CorsOrigins, self:custom.default.CorsOrigins}\r\n  cors:\r\n    origins: ${self:custom.currentVars.CorsOrigins}\r\n```\r\n* What stacktrace or error message from your provider did you see?\r\n```\r\n  Type Error ---------------------------------------------\r\n\r\n     cors.origins.join is not a function\r\n```\r\n\r\nAfter changing https://github.com/serverless/serverless/blob/master/lib/classes/Variables.js#L172 to ```valueToPopulate = undefined;``` the fallback option was loaded correctly. It appears that the `overwrite` function is checking for `undefined` or `null`. https://github.com/serverless/serverless/blob/master/lib/classes/Variables.js#L95\r\n\r\n## Additional Data\r\n\r\n* ***Serverless Framework Version you're using***: Master\r\n* ***Operating System***: Win 10\r\n* ***Stack Trace***: \r\n* ***Provider Error messages***:\r\n"},"comment":{"url":"https://api.github.com/repos/serverless/serverless/issues/comments/247359670","html_url":"https://github.com/serverless/serverless/issues/2081#issuecomment-247359670","issue_url":"https://api.github.com/repos/serverless/serverless/issues/2081","id":247359670,"user":{"login":"eahefnawy","id":2312463,"avatar_url":"https://avatars.githubusercontent.com/u/2312463?v=3","gravatar_id":"","url":"https://api.github.com/users/eahefnawy","html_url":"https://github.com/eahefnawy","followers_url":"https://api.github.com/users/eahefnawy/followers","following_url":"https://api.github.com/users/eahefnawy/following{/other_user}","gists_url":"https://api.github.com/users/eahefnawy/gists{/gist_id}","starred_url":"https://api.github.com/users/eahefnawy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eahefnawy/subscriptions","organizations_url":"https://api.github.com/users/eahefnawy/orgs","repos_url":"https://api.github.com/users/eahefnawy/repos","events_url":"https://api.github.com/users/eahefnawy/events{/privacy}","received_events_url":"https://api.github.com/users/eahefnawy/received_events","type":"User","site_admin":false},"created_at":"2016-09-15T15:21:13Z","updated_at":"2016-09-15T15:21:13Z","body":"@andymac4182 thanks for reporting this. This is an issue, but I think the solution is in the overwrite method to also overwrite if object is empty, something like this:\r\n\r\n```js\r\nreturn (typeof finalValue !== 'undefined' && finalValue !== null) && !_.isEmpty(finalValue);\r\n```\r\ncould you try something like that in your PR instead? 😊 \r\n\r\nThis reverting to empty object when it's undefined \"feature\" is a fix for an issue reported by @flomotlik a while back that allows us to deeply/recursively check non existing sub properties without throwing `can't read property of undefined` error. In other words, it makes the following overwrite works:\r\n\r\n```yml\r\ncustom:\r\n  testA: i am a string not object\r\n  testB: hello world\r\n  testC: ${self:custom.testA.some.invalid.property, self:custom.testB}\r\n```\r\nWithout this reverting to an empty object, we'd be trying to access the `invalid` sub property of an undefined `some` sub property, which of course throws an Error."}}
{"actor":{"display_login":"eahefnawy"}}