# Does remote\_file not support lazy attributes?

**URL:** <https://discourse.chef.io/t/does-remote-file-not-support-lazy-attributes/5161>\
**Category:** Chef Infra (archive)\
**Created:** [March 25, 2014, 11:58am UTC](https://discourse.chef.io/t/does-remote-file-not-support-lazy-attributes/5161 "2014-03-25T11:58:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeppe\_Nejsum\_Madsen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jeppe_nejsum_madsen/32/258_2.png) [@Jeppe\_Nejsum\_Madsen](https://discourse.chef.io/u/Jeppe_Nejsum_Madsen)\
**Post date:** [March 25, 2014, 11:58am UTC](https://discourse.chef.io/t/does-remote-file-not-support-lazy-attributes/5161/1 "2014-03-25T11:58:03Z")

</div>

I get the following when trying to use a lazy attribute:

This is the chef-shell.  
Chef Version: 11.10.4

chef:recipe \> remote\_file “/tmp/g2” do  
chef:recipe \> source lazy {“[http://www.google.com](http://www.google.com)”}  
chef:recipe ?\> end  
Chef::Exceptions::InvalidRemoteFileURI:  
#Chef::DelayedEvaluator:0x007fd464c092a8@(irb#1):7 is not a valid  
`source` parameter for remote\_file. `source` must be an absolute URI or an  
array of URIs.

Any hints?

/Jeppe

---

<div class="post-metadata">

**Author:** ![Steven\_Danna](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/steven_danna/32/195_2.png) [@Steven\_Danna](https://discourse.chef.io/u/Steven_Danna)\
**Post date:** [March 28, 2014, 4:48am UTC](https://discourse.chef.io/t/does-remote-file-not-support-lazy-attributes/5161/2 "2014-03-28T04:48:39Z")

</div>

Hi,

Unfortunately, this looks like a bug. When the lazy method is called,  
it creates a Chef::DelayedEvaluator object. This  
Chef::DelayedEvaluator is what gets passed to the source attribute's  
setter method in the resource. Most resource attribute setter methods  
use the helper function set\_or\_return(). When Chef::DelayedEvaluator  
was introduced, set\_or\_return was patched to ignore validatons if it  
got a DelayedEvaluator. The tradeoff for the power of lazy evaluation  
is no "compile phase" type checking of arguments.

remote\_file's source resource, however, uses a custom method for validation:

```
  def validate_source(source)
    raise ArgumentError, "#{resource_name} has an empty source" if

```

source.empty?  
source.each do |src|  
unless absolute\_uri?(src)  
raise Exceptions::InvalidRemoteFileURI,  
"#{src.inspect} is not a valid `source` parameter for  
#{resource\_name}. `source` must be an absolute URI or an array of  
URIs."  
end  
end  
end

This function and others like it need to be patched to accept  
DelayedEvaluators. I shall make with the typing into JIRA.

Sincerely,

Steven

On Tue, Mar 25, 2014 at 4:58 AM, Jeppe Nejsum Madsen [jeppe@ingolfs.dk](mailto:jeppe@ingolfs.dk) wrote:

> I get the following when trying to use a lazy attribute:
> 
> This is the chef-shell.  
> Chef Version: 11.10.4
> 
> chef:recipe \> remote\_file "/tmp/g2" do  
> chef:recipe \> source lazy {"[http://www.google.com](http://www.google.com)"}  
> chef:recipe ?\> end  
> Chef::Exceptions::InvalidRemoteFileURI:  
> #Chef::DelayedEvaluator:0x007fd464c092a8@(irb#1):7 is not a valid `source`  
> parameter for remote\_file. `source` must be an absolute URI or an array of  
> URIs.
> 
> Any hints?
> 
> /Jeppe

---

<div class="post-metadata">

**Author:** ![Steven\_Danna](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/steven_danna/32/195_2.png) [@Steven\_Danna](https://discourse.chef.io/u/Steven_Danna)\
**Post date:** [March 28, 2014, 6:26am UTC](https://discourse.chef.io/t/does-remote-file-not-support-lazy-attributes/5161/3 "2014-03-28T06:26:11Z")

</div>

Hi,

I've filed a bug on this here: [https://tickets.opscode.com/browse/CHEF-5162](https://tickets.opscode.com/browse/CHEF-5162)

Cheers,

Steven

On Thu, Mar 27, 2014 at 9:48 PM, Steven Danna [steve@opscode.com](mailto:steve@opscode.com) wrote:

> Hi,
> 
> Unfortunately, this looks like a bug. When the lazy method is called,  
> it creates a Chef::DelayedEvaluator object. This  
> Chef::DelayedEvaluator is what gets passed to the source attribute's  
> setter method in the resource. Most resource attribute setter methods  
> use the helper function set\_or\_return(). When Chef::DelayedEvaluator  
> was introduced, set\_or\_return was patched to ignore validatons if it  
> got a DelayedEvaluator. The tradeoff for the power of lazy evaluation  
> is no "compile phase" type checking of arguments.
> 
> remote\_file's source resource, however, uses a custom method for validation:
> 
> ```
> def validate_source(source)
> raise ArgumentError, "#{resource_name} has an empty source" if
> 
> ```
> 
> source.empty?  
> source.each do |src|  
> unless absolute\_uri?(src)  
> raise Exceptions::InvalidRemoteFileURI,  
> "#{src.inspect} is not a valid `source` parameter for  
> #{resource\_name}. `source` must be an absolute URI or an array of  
> URIs."  
> end  
> end  
> end
> 
> This function and others like it need to be patched to accept  
> DelayedEvaluators. I shall make with the typing into JIRA.
> 
> Sincerely,
> 
> Steven
> 
> On Tue, Mar 25, 2014 at 4:58 AM, Jeppe Nejsum Madsen [jeppe@ingolfs.dk](mailto:jeppe@ingolfs.dk) wrote:
> 
> > I get the following when trying to use a lazy attribute:
> > 
> > This is the chef-shell.  
> > Chef Version: 11.10.4
> > 
> > chef:recipe \> remote\_file "/tmp/g2" do  
> > chef:recipe \> source lazy {"[http://www.google.com](http://www.google.com)"}  
> > chef:recipe ?\> end  
> > Chef::Exceptions::InvalidRemoteFileURI:  
> > #Chef::DelayedEvaluator:0x007fd464c092a8@(irb#1):7 is not a valid `source`  
> > parameter for remote\_file. `source` must be an absolute URI or an array of  
> > URIs.
> > 
> > Any hints?
> > 
> > /Jeppe

---

<div class="post-metadata">

**Author:** ![Jeppe\_Nejsum\_Madsen](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jeppe_nejsum_madsen/32/258_2.png) [@Jeppe\_Nejsum\_Madsen](https://discourse.chef.io/u/Jeppe_Nejsum_Madsen)\
**Post date:** [March 30, 2014, 3:00pm UTC](https://discourse.chef.io/t/does-remote-file-not-support-lazy-attributes/5161/4 "2014-03-30T15:00:17Z")

</div>

Thanks!

/Jeppe

On Fri, Mar 28, 2014 at 7:26 AM, Steven Danna [steve@opscode.com](mailto:steve@opscode.com) wrote:

> Hi,
> 
> I've filed a bug on this here:  
> [https://tickets.opscode.com/browse/CHEF-5162](https://tickets.opscode.com/browse/CHEF-5162)
> 
> Cheers,
> 
> Steven
> 
> On Thu, Mar 27, 2014 at 9:48 PM, Steven Danna [steve@opscode.com](mailto:steve@opscode.com) wrote:
> 
> > Hi,
> > 
> > Unfortunately, this looks like a bug. When the lazy method is called,  
> > it creates a Chef::DelayedEvaluator object. This  
> > Chef::DelayedEvaluator is what gets passed to the source attribute's  
> > setter method in the resource. Most resource attribute setter methods  
> > use the helper function set\_or\_return(). When Chef::DelayedEvaluator  
> > was introduced, set\_or\_return was patched to ignore validatons if it  
> > got a DelayedEvaluator. The tradeoff for the power of lazy evaluation  
> > is no "compile phase" type checking of arguments.
> > 
> > remote\_file's source resource, however, uses a custom method for  
> > validation:
> > 
> > ```
> > def validate_source(source)
> > raise ArgumentError, "#{resource_name} has an empty source" if
> > 
> > ```
> > 
> > source.empty?  
> > source.each do |src|  
> > unless absolute\_uri?(src)  
> > raise Exceptions::InvalidRemoteFileURI,  
> > "#{src.inspect} is not a valid `source` parameter for  
> > #{resource\_name}. `source` must be an absolute URI or an array of  
> > URIs."  
> > end  
> > end  
> > end
> > 
> > This function and others like it need to be patched to accept  
> > DelayedEvaluators. I shall make with the typing into JIRA.
> > 
> > Sincerely,
> > 
> > Steven
> > 
> > On Tue, Mar 25, 2014 at 4:58 AM, Jeppe Nejsum Madsen [jeppe@ingolfs.dk](mailto:jeppe@ingolfs.dk)  
> > wrote:
> > 
> > > I get the following when trying to use a lazy attribute:
> > > 
> > > This is the chef-shell.  
> > > Chef Version: 11.10.4
> > > 
> > > chef:recipe \> remote\_file "/tmp/g2" do  
> > > chef:recipe \> source lazy {"[http://www.google.com](http://www.google.com)"}  
> > > chef:recipe ?\> end  
> > > Chef::Exceptions::InvalidRemoteFileURI:  
> > > #Chef::DelayedEvaluator:0x007fd464c092a8@(irb#1):7 is not a valid  
> > > `source`  
> > > parameter for remote\_file. `source` must be an absolute URI or an array  
> > > of  
> > > URIs.
> > > 
> > > Any hints?
> > > 
> > > /Jeppe
