Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3303

'@(...)' no longer allows collecting / copying of scalars from within a data container.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Rejected
    • Priority: High
    • Resolution: Done
    • Affects Version/s: 3.10.3, 3.15.1, 3.15.0-2
    • Fix Version/s: None
    • Component/s: Built-in functions
    • Labels:
      None

      Description

       

      We have a custom library which consumes JSON files, merges them together, and then exposes their contents as variables in a specific bundle.  We then use those bundle variables for templating.

      Creating the bundle variables is done as follows:

       

      "data1" data => mergedata( ... );
      "keys1" slist => getindices("data1");
      "keys1_canon[$(keys1)]" string => canonify($(keys1));
      "$(keys1_canon[$(keys1)])" data => @(data1[$(keys1)]);
      

      In 3.10.2 and prior, this worked for all data types.  The resulting variables could be scalars, slists, or data containers.  This is helpful for templating - the variable can be as simple or complex as required depending on the needs of that specific template.

      In 3.10.3 and later, for any key such that "data1[$(keys1)]" is a scalar, the final line fails with the message: "data1[key] is not mergeable as it it not a container".

      This appears to be a result of commit 641c404542f98a67fd092c8bc8a901f27fb1c0f0 for issue CFE-2704.  That commit/issue addressed a problem with the multi-argument use of mergedata( ... ).  However, the fix also changed the functionality of the single-argument usage invoked by @( ... ).

      The fix may also have introduced a regression when merging of classic arrays, as noted in CFE-2704.  However, the specific issue affecting us is the single-argument usage of @( ... ) when collecting a scalar value from within a data container.

      A fix for our use case could either revert the single-argument functionality of @( ... ) or provide a replacement function with equivalent functionality.

      I believe this is a minimal policy example of the regression:

       

       

      bundle agent main {
      	vars:
      		"data1" data => parsejson('{ "a": "a_val" }');
      		"a" data => @(data1[a]);
      	reports:
      		"a - $(a)";
      }
      

      It works fine in 3.10.2 and earlier:

      [root@example /]# cf-agent --version
      CFEngine Core 3.10.2
      [root@example /]# cf-agent -If /var/cfengine/inputs/minimal.cf 
      R: a - a_val
      

      It fails with errors on 3.10.3 and newer (including 3.15.1):

      [root@example /]# cf-agent --version
      CFEngine Core 3.15.1
      [root@example /]# cf-agent -If /var/cfengine/inputs/minimal.cf
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
      R: a - $(a)
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
         error: data1[a] is not mergeable as it it not a container
      

       

       

       

       

        Attachments

          Activity

            People

            • Assignee:
              a10042 Nick Anderson
              Reporter:
              joshpj Josh Jackson
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Summary Panel