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

Why Project_before_save_cw launches shared code for issues #208

Closed letitbe13 closed 1 year ago

letitbe13 commented 3 years ago

Hi! This is the only active cw in my redmine 3.4.6 (I reduced it to the minimum that still produces strange behavior) Project before_save:

   all_issues = self.issues
   self.children.select{|child| child.active?}.each do |child|
      all_issues.concat(child.issues)
   end

Production.log after project update (see my comments ###):

Started PATCH "/redmine/projects/nku" for 172.26.5.203 at 2021-02-21 15:47:51 +0300
Processing by ProjectsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"VHfY+ZIbcvFsT.............., "id"=>"nku"}
  Current user: redmine (id=1)
= Running shared code for Project (#1) "НКУ"  ###Parent project I updated
= Finished running shared code for Project (#1) "НКУ"
= Running before_save custom workflows for Project (#1) "НКУ"
== Running before_save custom workflow "Генератор отчета Проекта в поле "Описание"" ### THIS IS CW, I MENTIONED ABOVE ###
= Running shared code for Issue (#367) "Производство #367: Изготовление межсекционных жгутов" ### ? WHY? This is Child project issue ###
= Finished running shared code for Issue (#367) "Производство #367: Изготовление межсекционных жгутов"
= Running shared code for Issue (#657) "Проектирование #657: Выпуск документации" ### ? WHY? This is Child project issue ###
= Finished running shared code for Issue (#657) "Проектирование #657: Выпуск документации"
= Running shared code for Issue (#351) "Производство #351: Тестовая сборка выдвижных модулей"  ### ? WHY? This is Child project issue ###
= Finished running shared code for Issue (#351) "Производство #351: Тестовая сборка выдвижных модулей"
= Running shared code for Issue (#352) "Производство #352: Изготовление каркасов шкафов"  ### ? WHY? This is Child project issue ###
= Finished running shared code for Issue (#352) "Производство #352: Изготовление каркасов шкафов"
= Running shared code for Issue (#351) "Производство #351: Тестовая сборка выдвижных модулей" ### ? WHY? This is Child project issue ###
= Finished running shared code for Issue (#351) "Производство #351: Тестовая сборка выдвижных модулей"
= Running shared code for Issue (#352) "Производство #352: Изготовление каркасов шкафов"  ### ? WHY? This is Child project issue ###
= Finished running shared code for Issue (#352) "Производство #352: Изготовление каркасов шкафов"
== Custom workflow exception: Attempted to update a stale object: Issue ### ? AND FINALLY EVEN AN ACCESS ERROR? ###

If I don't mention children.issues in cw code, it doens't happen. How can I avoid running shared code for issues? I even don't understand what the code it is. I don't ask to update or save any issue...

AirTibu commented 3 years ago

Hi,

What is your exact intent with the code? If you could share it with us, there might be a different approach that could solve the problem.

Thanks!

letitbe13 commented 3 years ago

Hi,

What is your exact intent with the code? If you could share it with us, there might be a different approach that could solve the problem.

Thanks!

Thank you. I need to do a deep project report, based on all it issues including issues of all subprojects. I don’t need to update any issue, just read standard and custom fields. When I form an array of all issues that I’m going to deal with, unintentionally, cw of subproject issues start, and I can see it in a log. If I disable all cw for issues, I still can see in a log “running share code” for each subproject issue. How can I read issues properties from “Project before save cw” without running their custom workflows?..

picman commented 2 years ago

I've just tested it and it works as expected. Here is my my CW and the corresponding log output after a project save (I've 15 issues in the parent project and one issue in the sub-project):

Rails.logger.info ">>> Project #{self.name} is being updated"
all_issues = self.issues
  self.children.select{|child| child.active?}.each do |child|
  all_issues.concat child.issues
end
Rails.logger.info ">>> #{all_issues.size} issues"
Rails.logger.info '>>> Done'
= Running shared code for Project (#3342) "c1"
= Finished running shared code for Project (#3342) "c1"
= Running before_save custom workflows for Project (#3342) "c1"
== Running before_save custom workflow "c1"
>>> Project c1 is being updated
>>> 16 issues
>>> Done
= Finished running before_save custom workflows for Project (#3342) "c1"
= Running after_save custom workflows for Project (#3342) "c1"
= Finished running after_save custom workflows for Project (#3342) "c1"