# Params\[:file\] attributes lost within Scheduler::Defer

**URL:** <https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107>\
**Category:** Support\
**Created:** [12 Maggio 2016, 8:51am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107 "2016-05-12T08:51:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![williamherry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/williamherry/32/104524_2.png) [@williamherry](https://meta.discourse.org/u/williamherry)\
**Post date:** [12 Maggio 2016, 8:51am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/1 "2016-05-12T08:51:43Z")

</div>

I deployed a instance manually on a centos host, image upload does not work, after several hours of debug, I find file in Scheduler::Defer block lost some attribites, see debug code below

```
def create
    type = params.require(:type)
    file = params[:file] || params[:files].try(:first)
    url = params[:url]
    client_id = params[:client_id]
    synchronous = is_api? && params[:synchronous]

    if type == "avatar"
      if SiteSetting.sso_overrides_avatar || !SiteSetting.allow_uploaded_avatars
        return render json: failed_json, status: 422
      end
    end

    Rails.logger.error(file.tempfile.path) # =>url

    if true #synchronous
      data = create_upload(type, file, url)
      render json: data.as_json
    else
      Scheduler::Defer.later("Create Upload") do
        Rails.logger.error(file.tempfile.path) # => nil
        data = create_upload(type, file, url)
        MessageBus.publish("/uploads/#{type}", data.as_json, client_ids: [client_id])
      end
      render json: success_json
    end
  end

```

any one know what’s going on here?

---

<div class="post-metadata">

**Author:** ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)\
**Post date:** [12 Maggio 2016, 8:56am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/2 "2016-05-12T08:56:54Z")

</div>

Let me have a look and try to repro locally.

---

<div class="post-metadata">

**Author:** ![williamherry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/williamherry/32/104524_2.png) [@williamherry](https://meta.discourse.org/u/williamherry)\
**Post date:** [12 Maggio 2016, 3:38pm UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/3 "2016-05-12T15:38:51Z")

</div>

I think it’s not easy to repro, I run development environment on ubuntu and mac all works, this problem only occur on a centos host with production environment, and I am not using docker to install that

---

<div class="post-metadata">

**Author:** ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)\
**Post date:** [12 Maggio 2016, 4:49pm UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/4 "2016-05-12T16:49:37Z")

</div>

Yeah I can’t repro locally ☹ I’m afraid you’re on your own here (_CentOS + non-docker install_).

---

<div class="post-metadata">

**Author:** ![williamherry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/williamherry/32/104524_2.png) [@williamherry](https://meta.discourse.org/u/williamherry)\
**Post date:** [13 Maggio 2016, 2:45am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/5 "2016-05-13T02:45:22Z")

</div>

I will post the info I get so far in case some one interested

Now I can narrow down the problem to: when use unicorn, object within `Scheduler::Defer.later` block will lost their instance\_variables

```
a = "1"
a.instance_variable_set('@a', 1)
Rails.logger.error(a.instance_values) # => {"a"=>1}
Scheduler::Defer.later("Create Upload") do
  Rails.logger.error(a.instance_values) # => nothing
end

```

If I start a console by `rails c` and run above code, the result is as expected,

after switch to thin, image upload works

unicorn also not work on my development machine, which is ubuntu, but the result is a little bit different: the instance\_varialbes remains, but the tempfile is show closed, call path on that return nil

```
{"tempfile"=>#<Tempfile: (closed)>, "original_filename"=>"favicons.png", "content_type"=>"image/png", "headers"=>"Content-Disposition: form-data; name=\"files[]\"; filename=\"favicons.png\"\r\nContent-Type: image/png\r\n"}

```

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [13 Maggio 2016, 2:56am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/6 "2016-05-13T02:56:13Z")

</div>

Duplicate:

[https://meta.discourse.org/t/tempfile-is-nil-on-defered-uploads/34513?u=falco](https://meta.discourse.org/t/tempfile-is-nil-on-defered-uploads/34513)

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [19 Gennaio 2019, 12:07am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/7 "2019-01-19T00:07:17Z")

</div>



---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [19 Gennaio 2019, 12:09am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/8 "2019-01-19T00:09:15Z")

</div>

[https://meta.discourse.org/t/tempfile-is-nil-on-defered-uploads/34513/13?u=falco](https://meta.discourse.org/t/tempfile-is-nil-on-defered-uploads/34513/13)

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [19 Gennaio 2019, 12:09am UTC](https://meta.discourse.org/t/params-file-attributes-lost-within-scheduler-defer/44107/9 "2019-01-19T00:09:18Z")

</div>


