{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla/nunjucks/issues/481","repository_url":"https://api.github.com/repos/mozilla/nunjucks","labels_url":"https://api.github.com/repos/mozilla/nunjucks/issues/481/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/nunjucks/issues/481/comments","events_url":"https://api.github.com/repos/mozilla/nunjucks/issues/481/events","html_url":"https://github.com/mozilla/nunjucks/pull/481","id":96440550,"number":481,"title":"Respect explicitly-set undefined or null values in a frame.","user":{"login":"carljm","id":61586,"avatar_url":"https://avatars.githubusercontent.com/u/61586?v=3","gravatar_id":"","url":"https://api.github.com/users/carljm","html_url":"https://github.com/carljm","followers_url":"https://api.github.com/users/carljm/followers","following_url":"https://api.github.com/users/carljm/following{/other_user}","gists_url":"https://api.github.com/users/carljm/gists{/gist_id}","starred_url":"https://api.github.com/users/carljm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carljm/subscriptions","organizations_url":"https://api.github.com/users/carljm/orgs","repos_url":"https://api.github.com/users/carljm/repos","events_url":"https://api.github.com/users/carljm/events{/privacy}","received_events_url":"https://api.github.com/users/carljm/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mozilla/nunjucks/labels/patch-needs-improvement","name":"patch-needs-improvement","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-21T23:40:55Z","updated_at":"2016-02-17T23:44:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mozilla/nunjucks/pulls/481","html_url":"https://github.com/mozilla/nunjucks/pull/481","diff_url":"https://github.com/mozilla/nunjucks/pull/481.diff","patch_url":"https://github.com/mozilla/nunjucks/pull/481.patch"},"body":"This fixes #478, which is a nasty subtle bug that leads to very strange and difficult-to-diagnose behaviors in calling template macros with arguments whose default value is `none`.\r\n\r\nThe core of the problem is nunjucks' loose handling of `null` and `undefined` in symbol value lookups. Symbol values are looked up at runtime using `contextOrFrameLookup`. If the frame lookup returns `null` or `undefined`, `contextOrFrameLookup` considers that a \"not found\" and looks up the name in the context instead. Similarly, with stacked frames, if an `undefined` or `null` value is found for the name in one frame, it ignores that and goes up to the parent frame instead. This means that you effectively cannot have a variable explicitly set to a value of `undefined` or `null` in a scope - if a parent scope (frame or context) has some other value for that symbol name, it will be used instead.\r\n\r\nThis pull request changes that behavior to instead use `hasOwnProperty` to determine whether a variable is present in a given frame or not, and never go up the frame stack (or fall back to context) if the variable is present, regardless of its value.\r\n\r\n(If #480 is accepted, this PR could be changed to still consider `undefined` the same as \"not found\", but support `null`. That would be enough to support variables being set to `none`, which is really the motivating use case here.)"},"comment":{"url":"https://api.github.com/repos/mozilla/nunjucks/issues/comments/185461805","html_url":"https://github.com/mozilla/nunjucks/pull/481#issuecomment-185461805","issue_url":"https://api.github.com/repos/mozilla/nunjucks/issues/481","id":185461805,"user":{"login":"carljm","id":61586,"avatar_url":"https://avatars.githubusercontent.com/u/61586?v=3","gravatar_id":"","url":"https://api.github.com/users/carljm","html_url":"https://github.com/carljm","followers_url":"https://api.github.com/users/carljm/followers","following_url":"https://api.github.com/users/carljm/following{/other_user}","gists_url":"https://api.github.com/users/carljm/gists{/gist_id}","starred_url":"https://api.github.com/users/carljm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carljm/subscriptions","organizations_url":"https://api.github.com/users/carljm/orgs","repos_url":"https://api.github.com/users/carljm/repos","events_url":"https://api.github.com/users/carljm/events{/privacy}","received_events_url":"https://api.github.com/users/carljm/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T23:44:51Z","updated_at":"2016-02-17T23:44:51Z","body":"@jgerigmeyer The \"new\" bug you mention in your follow-up here isn't new with this PR, it's the existing behavior of nunjucks and unrelated to this PR. It's a combination of two things: 1) in Jinja2 `none` renders as `None`, whereas in nunjucks it renders as the empty string -- not sure if I even consider this a bug that needs to be fixed, and 2) In nunjucks you can't reference vars from enclosing scopes from within a `{% call %}` block, whereas in Jinja2 you can -- this is I think related to #664."}}