Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71909

active choice updates in wrong order (does not Cascade the values correctly)

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • active-choices-plugin
    • None
    • clean jenkins docker latest LTS: 2.414.3, with the recommended plugins + active-choice plugin(2.8.0) installed

      With the new version of the active-choice plugin 2.7.1, 2.7.2, 2.8.0, 2.8.1 the recursive update of the elements are not always working as expected. This working just fine with the previous release 2.6.5

      With the latest LTS jenkins version 2.426.1 the issue is still present, also the old version of the plugin 2.6.5 is not compatible anymore with the latest Jenkins (maybe because the removed prototype.js ?).

      The sample Free style task contains 4 elements:
      1) Choice Parameter: TARGET with values:

      Item1
      Item2
      Item3

      2)  Active Choices Reactive Parameter: VARIANT, Radio Buttons, Referenced parameters=TARGET; groovy script:

       

      dynRefParam = "a1:selected a2"
      if( TARGET.equals( "Item2" ) ) 
          {
              dynRefParam = "a2:selected"
          }
      return dynRefParam.tokenize()
      

       

      3) Active Choices Reactive Parameter: MACHINES, Check Boxes, Referenced parameters: TARGET,VARIANT; groovy script:

       

      dynRefParam = "unavailable_machines"
      if ( VARIANT.equals( "a1" ) )
      {
          dynRefParam = "server1 server2 server4 server5"
      }
      if ( TARGET.equals( "Item2" ))
      {
          if ( VARIANT.equals( "a2" ) )
          {
              dynRefParam = "server1:selected"
          }
      } else if ( TARGET.equals( "Item1" ))
      {
          dynRefParam = "server2:selected server3:selected"
      }
      return dynRefParam.tokenize()
      

       

      4) Active Choices Reactive Parameter: DOCKER_BASE_IMAGE, Radio Boxes, Referenced parameters: MACHINES; groovy script:

       

      dynRefParam ="buster:selected bullseye"
      if ( MACHINES.contains( "server1" ) || MACHINES.contains( "server2" ) || MACHINES.contains( "server3" ))
      {
          dynRefParam ="buster bullseye:selected"
      }
      return dynRefParam.tokenize()
      

       

       

      The issue is when "Item2" is selected, then the 4) active-choice elements returns as selected "buster" instead of "bullseye", this because, when first called the wrong server list is returned from 3), because 3) is called with "a1" as parameter instead of "a2" as should be after the 2) gets executed.

      If Item2 is selected then from the MACHINES, server1 is de-selected then selected again, than the DOCKER_BASE_IMAGE selects correctly the  bullseye.

      Here is the full config.xml saved from the docker image:

       

      <?xml version='1.1' encoding='UTF-8'?>
      <project>
        <actions/>
        <description></description>
        <keepDependencies>false</keepDependencies>
        <properties>
          <hudson.model.ParametersDefinitionProperty>
            <parameterDefinitions>
              <hudson.model.ChoiceParameterDefinition>
                <name>TARGET</name>
                <choices class="java.util.Arrays$ArrayList">
                  <a class="string-array">
                    <string>Item1</string>
                    <string>Item2</string>
                    <string>Item3</string>
                  </a>
                </choices>
              </hudson.model.ChoiceParameterDefinition>
              <org.biouno.unochoice.CascadeChoiceParameter plugin="uno-choice@2.7.2">
                <name>VARIANT</name>
                <randomName>choice-parameter-538043095727729</randomName>
                <visibleItemCount>1</visibleItemCount>
                <script class="org.biouno.unochoice.model.GroovyScript">
                  <secureScript plugin="script-security@1273.v66c1964f0dfd">
                    <script>dynRefParam = &quot;a1:selected a2&quot;
      if( TARGET.equals( &quot;Item2&quot; ) )
              {
                      dynRefParam = &quot;a2:selected&quot;
              }
      return dynRefParam.tokenize()</script>
                    <sandbox>true</sandbox>
                  </secureScript>
                  <secureFallbackScript plugin="script-security@1273.v66c1964f0dfd">
                    <script>return [&quot;Script error&quot;]</script>
                    <sandbox>true</sandbox>
                  </secureFallbackScript>
                </script>
                <projectName>test</projectName>
                <projectFullName>test</projectFullName>
                <parameters class="linked-hash-map"/>
                <referencedParameters>TARGET</referencedParameters>
                <choiceType>PT_RADIO</choiceType>
                <filterable>false</filterable>
                <filterLength>1</filterLength>
              </org.biouno.unochoice.CascadeChoiceParameter>
              <org.biouno.unochoice.CascadeChoiceParameter plugin="uno-choice@2.7.2">
                <name>MACHINES</name>
                <randomName>choice-parameter-538043138290364</randomName>
                <visibleItemCount>1</visibleItemCount>
                <script class="org.biouno.unochoice.model.GroovyScript">
                  <secureScript plugin="script-security@1273.v66c1964f0dfd">
                    <script>dynRefParam = &quot;unavailable_machines&quot;
      if ( VARIANT.equals( &quot;a1&quot; ) )
      {
              dynRefParam = &quot;server1 server2 server4 server5&quot;
      }
      if ( TARGET.equals( &quot;Item2&quot; ))
      {
              if ( VARIANT.equals( &quot;a2&quot; ) )
              {
                      dynRefParam = &quot;server1:selected&quot;
              }
      } else if ( TARGET.equals( &quot;Item1&quot; ))
      {
              dynRefParam = &quot;server2:selected server3:selected&quot;
      }
      return dynRefParam.tokenize()</script>
                    <sandbox>true</sandbox>
                  </secureScript>
                  <secureFallbackScript plugin="script-security@1273.v66c1964f0dfd">
                    <script>return [&quot;Script error&quot;]</script>
                    <sandbox>true</sandbox>
                  </secureFallbackScript>
                </script>
                <projectName>test</projectName>
                <projectFullName>test</projectFullName>
                <parameters class="linked-hash-map"/>
                <referencedParameters>TARGET,VARIANT</referencedParameters>
                <choiceType>PT_CHECKBOX</choiceType>
                <filterable>false</filterable>
                <filterLength>1</filterLength>
              </org.biouno.unochoice.CascadeChoiceParameter>
              <org.biouno.unochoice.CascadeChoiceParameter plugin="uno-choice@2.7.2">
                <name>DOCKER_BASE_IMAGE</name>
                <randomName>choice-parameter-538043144523822</randomName>
                <visibleItemCount>1</visibleItemCount>
                <script class="org.biouno.unochoice.model.GroovyScript">
                  <secureScript plugin="script-security@1273.v66c1964f0dfd">
                    <script>dynRefParam =&quot;buster:selected bullseye&quot;
      if ( MACHINES.contains( &quot;server1&quot; ) || MACHINES.contains( &quot;server2&quot; ) || MACHINES.contains( &quot;server3&quot; ))
      {
              dynRefParam =&quot;buster bullseye:selected&quot;
      }
      return dynRefParam.tokenize()</script>
                    <sandbox>true</sandbox>
                  </secureScript>
                  <secureFallbackScript plugin="script-security@1273.v66c1964f0dfd">
                    <script>return [&quot;Script error&quot;]</script>
                    <sandbox>true</sandbox>
                  </secureFallbackScript>
                </script>
                <projectName>test</projectName>
                <projectFullName>test</projectFullName>
                <parameters class="linked-hash-map"/>
                <referencedParameters>MACHINES</referencedParameters>
                <choiceType>PT_RADIO</choiceType>
                <filterable>false</filterable>
                <filterLength>1</filterLength>
              </org.biouno.unochoice.CascadeChoiceParameter>
            </parameterDefinitions>
          </hudson.model.ParametersDefinitionProperty>
        </properties>
        <scm class="hudson.scm.NullSCM"/>
        <canRoam>true</canRoam>
        <disabled>false</disabled>
        <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
        <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
        <triggers/>
        <concurrentBuild>false</concurrentBuild>
        <builders/>
        <publishers/>
        <buildWrappers/>
      </project>
      

      Here is the "Console" log output from Firefox:

      Cascading changes from parameter TARGET... 2 UnoChoice.js:1:6332
      Values retrieved from Referenced Parameters: TARGET=Item2 UnoChoice.js:1:8457
      Values retrieved from Referenced Parameters: TARGET=Item2__LESEP__VARIANT=a1 UnoChoice.js:1:8457
      Calling Java server code to update HTML elements... 2 UnoChoice.js:1:8599
      Values returned from server: a2:selected,a2:selected UnoChoice.js:1:8738
      Updating MACHINES from VARIANT UnoChoice.js:1:12066
      Values retrieved from Referenced Parameters: TARGET=Item2__LESEP__VARIANT=a2 UnoChoice.js:1:8457
      Values returned from server: server1,server2,server4,server5,server1,server2,server4,server5 UnoChoice.js:1:8738
      Updating DOCKER_BASE_IMAGE from MACHINES UnoChoice.js:1:12066
      Values retrieved from Referenced Parameters: MACHINES= UnoChoice.js:1:8457
      Calling Java server code to update HTML elements... 2 UnoChoice.js:1:8599
      Values returned from server: buster:selected,bullseye,buster:selected,bullseye UnoChoice.js:1:8738
      Avoiding infinite loop due to recursion! UnoChoice.js:1:12169
      Values returned from server: server1:selected,server1:selected UnoChoice.js:1:8738
      Avoiding infinite loop due to recursion! UnoChoice.js:1:12169

      In fact this was originally reported in JENKINS-71724, but then the null issue was fixed, this originally reported issue remained.

       

          [JENKINS-71909] active choice updates in wrong order (does not Cascade the values correctly)

          rahulsom , kinow I feel that if the asynchronous/promises change is the cause for incorrect AC parameter updates we need to revert to the code before 2.7. Cascade updates was the whole point of Active Choices. If that functionality is unreliable/broken I suggest we either revert to pre v2.7 approach or rename the plugin to 'Broken Promises'  

          Ioannis Moutsatsos added a comment - rahulsom , kinow I feel that if the asynchronous/promises change is the cause for incorrect AC parameter updates we need to revert to the code before 2.7. Cascade updates was the whole point of Active Choices. If that functionality is unreliable/broken I suggest we either revert to pre v2.7 approach or rename the plugin to 'Broken Promises'  

          Bruno P. Kinoshita added a comment - - edited

          Reverting this! Starting today, cannot promise if it will be done this weekend (or undone).

          Bruno P. Kinoshita added a comment - - edited Reverting this! Starting today, cannot promise if it will be done this weekend (or undone).

          Bruno P. Kinoshita added a comment - Change to be reverted: https://github.com/jenkinsci/active-choices-plugin/pull/79

          I think the revert is done, but the UiAcceptanceTest may need some rework before it's fixed/reverted. Some of the code added were good improvements, and I am afraid code added after that used the new functions.

          https://github.com/jenkinsci/active-choices-plugin/pull/298

          If anyone needs/wants this merged soon, please consider testing and/or reviewing the merge request, that would be of great help! Gotta go now, will continue with the tests next time. I created a job with the OP's description of the issue, and am able to reproduce it locally. The idea is that if the PR fixes that, and the case provided by the issue reporter is fixed, then it should be ready to be released.

          Bruno P. Kinoshita added a comment - I think the revert is done, but the UiAcceptanceTest may need some rework before it's fixed/reverted. Some of the code added were good improvements, and I am afraid code added after that used the new functions. https://github.com/jenkinsci/active-choices-plugin/pull/298 If anyone needs/wants this merged soon, please consider testing and/or reviewing the merge request, that would be of great help! Gotta go now, will continue with the tests next time. I created a job with the OP's description of the issue, and am able to reproduce it locally. The idea is that if the PR fixes that, and the case provided by the issue reporter is fixed, then it should be ready to be released.

          Jon added a comment - - edited

          The random order of elements is causing issues for me as well.  I happened across this page today, I'll check out the PR and see if it fixes my issue.

          I see the UiAcceptanceTest hangs after launching the browser; I haven't looked into that further yet.

          The rest of the tests fail because the makeStaplerProxy2() is looking for Prototype and the Ajax object doesn't exist.  I'm not sure what the appropriate fix is - the comments mention that makeStaplerProxy2 is like makeStaplerProxy() but synchronous, so I assume that is important, so perhaps makeStaplerProxy2() does need to exist, but change the jQuery/Prototype check?

          I bypassed the tests, but unsuprisingly, the code fails due to that function not working.  I'll see about re-adding that one function.

          Jon added a comment - - edited The random order of elements is causing issues for me as well.  I happened across this page today, I'll check out the PR and see if it fixes my issue. I see the UiAcceptanceTest hangs after launching the browser; I haven't looked into that further yet. The rest of the tests fail because the makeStaplerProxy2() is looking for Prototype and the Ajax object doesn't exist.  I'm not sure what the appropriate fix is - the comments mention that makeStaplerProxy2 is like makeStaplerProxy() but synchronous, so I assume that is important, so perhaps makeStaplerProxy2() does need to exist, but change the jQuery/Prototype check? I bypassed the tests, but unsuprisingly, the code fails due to that function not working.  I'll see about re-adding that one function.

          All tests passing on the PR for this issue. Now back to running some manual tests before that PR is ready to be reviewed (might try to write a test to avoid a regression like this, but not sure how difficult that is).

          Bruno P. Kinoshita added a comment - All tests passing on the PR for this issue. Now back to running some manual tests before that PR is ready to be reviewed (might try to write a test to avoid a regression like this, but not sure how difficult that is).

          Couldn't reproduce the issue!

          Could somebody else try the version from https://github.com/jenkinsci/active-choices-plugin/pull/298, please? Will ask over there as well.

          Bruno P. Kinoshita added a comment - Couldn't reproduce the issue! Could somebody else try the version from https://github.com/jenkinsci/active-choices-plugin/pull/298, please? Will ask over there as well.

          In 2.8.4 (release in progress)

          Bruno P. Kinoshita added a comment - In 2.8.4 (release in progress)

          Wait some hours/day, then please check 2.8.4 from the update site, and let me know if you find this issue (or similar with reactivity) again. Cheers.

          Bruno P. Kinoshita added a comment - Wait some hours/day, then please check 2.8.4 from the update site, and let me know if you find this issue (or similar with reactivity) again. Cheers.

          Hossted added a comment - - edited

          Greetings!

          We are also a community member experiencing the similar issue.

          We hired professional expert(s) to work on this matter since our business case demanded so.
          We submitted the dedicated issue describing the problem(s) in detail here:
          JENKINS-73935

          We hope that the plugin maintainer(s) and / or author(s) will be able to fix the root cause of this issue in the near future.

          In the meantime, we created a separate repository project which contains a workaround for this issue.

          For more information, you can check it out here (on our GitHub).

          Please read in detail if you are interested.
          Also, we provided a patched plugin bundles containing the fix here (on our GitHub).

          But due to security concerns, please, use with caution.

          If you are interested in using the fix before the official fix from the maintainer(s), it would be preferred that you rebuild it yourself instead of using our pre-built bundle we are distributing.

           

          Best regards,
          Hossted

          Hossted added a comment - - edited Greetings! We are also  a community member  experiencing the similar issue. We hired professional expert(s) to work on this matter since our business case demanded so. We submitted the dedicated issue describing the problem(s) in detail here: JENKINS-73935 We hope that the  plugin maintainer(s) and / or author(s) will be able to fix the root cause of this issue  in the near future. In the meantime, we created a separate repository project which contains a workaround for this issue. For more information, you can check it out  here (on our GitHub) . Please read in detail if you are interested. Also, we provided a patched plugin bundles containing the fix  here (on our GitHub) . But due to security concerns, please, use with caution. If you are interested in using the fix before the official fix from the maintainer(s), it would be preferred that you rebuild it yourself instead of using our pre-built bundle we are distributing.   Best regards, Hossted

            kinow Bruno P. Kinoshita
            szjozsef Jozsef
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: