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

StaplerRequest.getAncestor does not work for lazy block

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            jglick Jesse Glick added a comment -

            Implementation of JENKINS-26093 needs this workaround (originally done in cloudbees-template).

            Show
            jglick Jesse Glick added a comment - Implementation of JENKINS-26093 needs this workaround (originally done in cloudbees-template ).
            Hide
            jglick Jesse Glick added a comment -

            Might prevent JENKINS-20959 from being implemented without regressions.

            Show
            jglick Jesse Glick added a comment - Might prevent JENKINS-20959 from being implemented without regressions.
            Hide
            jglick Jesse Glick added a comment -

            Affects c:select in a Snippet Generator form using Credentials 2.x as of 9c5bb72 Stephen Connolly: CredentialsSelectHelper tries to call findAncestorObject(ModelObject.class) and gets nothing.

            Show
            jglick Jesse Glick added a comment - Affects c:select in a Snippet Generator form using Credentials 2.x as of 9c5bb72 Stephen Connolly : CredentialsSelectHelper tries to call findAncestorObject(ModelObject.class) and gets nothing.
            Hide
            jglick Jesse Glick added a comment -

            @ContextInPath as defined by Stephen Connolly might be useful here.

            Show
            jglick Jesse Glick added a comment - @ContextInPath as defined by Stephen Connolly might be useful here.

              People

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

                Dates

                • Created:
                  Updated: