Skip to content

Expected behaviour of push/npush/npush_if #104

@stdweird

Description

@stdweird

While working on #102, i stumbled on some ill defined behaviour of push (which also exists in npush and push_if)

object template push;

include 'pan/functions';

"/functions/push_dml_empty/data" = {
    foreach(idx;id;list(1,2,3)) {
        push(id);
    };
};

"/functions/push_dml_nonempty/data/0" = 0;
"/functions/push_dml_nonempty/data" = {
    foreach(idx;id;list(1,2,3)) {
        push(id);
    };
};

current master returns

{
  "functions": {
    "push_empty": {
      "data": [
        3
      ]
    },
    "push_nonempty": {
      "data": [
        0,
        1,
        2,
        3
      ]
    }
  }
}

so there is a significance difference between push depending on the the existence of SELF (the reimplementation using merge as in the PR suffers from similar yet different problems. (chagning the code and ending with SELF; gives different issues altogether, but they are still different).

my question is: how to handle this. keep the old code, but warn in the doc that push/npush/push_if have undesired sideeffects in DML blocks?

some sanity could be restored by using append in push/push_if, but there is no equivalent of append for dicts (in particular, merge with single argument to update SELF is not supported; see quattor/pan#103).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions