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

StaplerRequest.getAncestor does not work for lazy block

      It is a common trick to use StaplerRequest.getAncestor to find the model object being configured in a form so that Java code run on the back end can have some context. This works fine if the configuration block was part of the main page load. But if it was injected in a lazy block, e.g. by adding a repeatable section, the request URI is /$stapler/bound/.../render and there are no ancestors, so getAncestor quietly returns null!

      This is especially insidious because you may iteratively test a feature relying on getAncestor successfully, by reloading .../configure after making code changes; but if you never try adding the section for the first time you might never notice this problem.

      The workaround is to check for a Referer header and manually parse this out to find the model object of interest. But Stapler ought to do this for you automatically.

          [JENKINS-19413] StaplerRequest.getAncestor does not work for lazy block

          Jesse Glick created issue -
          Jesse Glick made changes -
          Link New: This issue is blocking JENKINS-26093 [ JENKINS-26093 ]
          Jesse Glick made changes -
          Labels Original: jelly stapler New: jelly stapler workflow
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-24165 [ JENKINS-24165 ]
          Jesse Glick made changes -
          Link New: This issue is blocking JENKINS-20959 [ JENKINS-20959 ]
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-36315 [ JENKINS-36315 ]
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 150862 ] New: JNJira + In-Review [ 177793 ]
          Andrew Bayer made changes -
          Labels Original: jelly stapler workflow New: jelly pipeline stapler workflow
          Andrew Bayer made changes -
          Labels Original: jelly pipeline stapler workflow New: jelly pipeline stapler
          Jesse Glick made changes -
          Remote Link New: This issue links to "Discussion of @ContextInPath (Web Link)" [ 22353 ]
          Jesse Glick made changes -
          Labels Original: jelly pipeline stapler New: api jelly pipeline stapler

            Unassigned Unassigned
            jglick Jesse Glick
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: