anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
182 stars 72 forks source link

Custom values retrieving before issue destroy #278

Closed kty0mka closed 2 years ago

kty0mka commented 2 years ago

Hi!

I'm trying to retrieve custom values in before_destroy workflow, but get only empty values:

self.custom_field_value(cfv_id)
=> nil

also:

CustomValue.where(customized_id: self.id)
=> []

But at the same time I could retrieve custom values with above command directly in rails console:

  1. Create custom workflow with any method to retrieve custom values and long delay in before_destroy section, e.g.
    ### before_delete start
    self_id_s = "#{self.id}"
    puts "self_id: #{self_id_s}"
    puts CustomValue.where(customized_id: self_id_s).to_a.map(&:serializable_hash)
    puts "before sleep"
    sleep 100
    puts "after sleep"
    puts "end del"
    ### before_delete end
  2. Run issue delete
  3. Looking in Redmine logs:
    self_id: my_issue_id
    []
    before sleep
  4. Trying to retrieve custom values in rails console
    bundle exec rails c -e production
    irb(main)> CustomValue.where(customized_id: my_issue_id)
    => [here is desired custom values, everything is ok]
  5. Also look at database directly: custom_values table contains required values, everything is ok.
  6. Workflow (and delay) ends:
  7. Redmine logs:
    after sleep
    end del
  8. Rails output
    irb(main)> CustomValue.where(customized_id: my_issue_id)
    => [] # no custom values as expected
  9. DB's custom_values table do not contains required values, as expected.

Summary: when running before_destroy custom values still exist in DB (as expected), I could retrieve them in rails console (as expected), but could not retrieve them in workflow (unexpected).

What am I doing wrong? If there is a way to retrieve custom values in before_delete?

picman commented 2 years ago

Unfortunately, custom values are deleted before _afterdestroy is triggered (in Redmine). So, values are no more available at the moment of processing custom workflow script. I don't see any way how to get them.

picman commented 2 years ago

Maybe, you can stash them in _beforedestroy for a later usage in _afterdestroy.

Seahawk240 commented 1 year ago

@picman I've got the same problem using before_destroy for time_entries. My Custom_Values is always empty. @kty0mka did you find a solution?

picman commented 1 year ago

You are right. They are gone even in _beforedestroy.