Dashboard not showing Select's 3rd argument

Good afternoon,
While updating some UDF’s on the dashboard, I realized the Select method is not showing the 3rd argument and then it updates with 2 arguments, so the 3rd is lost forever. I usually set up some fallbacks to handle known exceptions.
¿can you help me here?
Thanks a lot

Hi @Sertge,

would you share the UDF, a document sample and what you are trying to achieve?

Luigi

Query(
  Lambda(
["user", "anonymous"],
Let(
  {
    existingChat: Match(Index("chatsByUser"), Var("user")),
    chatDoc: If(
      Equals(Count(Var("existingChat")), 0),
      Create(Collection("Chats"), {
        data: {
          users: [Identity(), Var("user")],
          anonymous: Var("anonymous")
        }
      }),
      Get(Select(["data", 0, 1], Paginate(Var("existingChat"))))
    ),
    users: Select(["data", "users"], Var("chatDoc")),
    nicknames: Prepend(
      [
        Select(
          [
            "data",
            If(
              Select(["data", "anonymous"], Var("chatDoc")),
              "anonymName",
              "displayName"
            )
          ],
          Get(Select(0, Var("users")))
        )
      ],
      Map(
        Drop(1, Var("users")),
        Lambda("user", Select(["data", "displayName"], Get(Var("user"))))
      )
    ),
    profilePicture: Prepend(
      [
        If(
          Select(["data", "anonymous"], Var("chatDoc")),
          "",
          Select(["data", "profilePicture"], Get(Select(0, Var("users"))))
        )
      ],
      Map(
        Drop(1, Var("users")),
        Lambda("user", Select(["data", "profilePicture"], Get(Var("user"))))
      )
    )
  },
  Merge(Var("chatDoc"), {
    nicknames: Var("nicknames"),
    profilePicture: Var("profilePicture"),
    ownRef: Identity()
  })
)
  )
)

This function is supposed to have fallbacks on the nickname Selects as well as the anonymous Selects, however, they are not showing here. When I update, it gets saved with 2 arguments, losing the 3rd one and returning bugs

When I set up an UDF on Fauna’s dashboard, I put 3 arguments on the Select method and save the function, then I update the page to see my UDF and the 3rd argument in the Select is missing. When I update the function, Select is saved with 2 arguments, thus, there will be no fallback and in case of a missing field on a document/query/etc, Fauna will return error.

Hi there! some help can be appreciated @ptpaterson and @databrecht, thanks in advance!

Hi @davidlondonor, I feel special for the shout out! But I don’t think I can help. It might be a bug in the javascript driver. I don’t work at fauna and can’t help with that.

I can confirm that changing one part to:

Select(["data", "anonymous"], Var("chatDoc"), false) // added false as default

and refreshing shows that the false is nolonger there.

@Sertge I will say that it is likely that the function is fine to use, but a terrible terrible pain that it is not printing back correctly.

Do you manage your functions in a script and upload them or are you only working from the dashboard? You might be able to get some more peace of mind from saving the FQL in version control and knowing that if the upload works, it matches the FQL you sent.

1 Like

Hi @Sertge,
I tried compiling a function with the below code:

CreateFunction({name:"testFunc",body:Query(Lambda('x',Select(['data','val3','val5'],Get(Var('x')),null)))})

and then updated many times with:

Update(Function('testFunc'),{body:Query(Lambda('x',Select(['data','val3','val5'],Get(Var('x')),null)))})

but the third Select argument is still present.
Do I miss something in reproducing the issue you are having?

Luigi Servini

Hello @Luigi_Servini,
Are you doing this via the dashboard’s function editor?
That’s the section I’m having issues with.
I may be wrong, but by the code lines you’re using, it looks like you’re doing it via Shell.
On the Fauna’s dashboard function editor, I write something like this:
Query(Lambda("x", Select("something", Var("x"),null)))
And when I update the page, I get something like this:
Query(Lambda("x", Select("something", Var("x"))))
When I have larger functions, it’s easy to miss a Select with no 3rd argument and save it with only 2, so I get some bugs.

Hello @ptpaterson,
Would you please elaborate on the version control part?
Do you mean putting the functions on my APIs and send the query to Fauna when I need to use it?
or is there a way of putting Fauna functions on version control? (I would love to hear from this)

Thank you so much for your time

I mean that you can use a setup script to run queries directly.

That is, use the javascript (or language of your choice) driver to run Create and/or Update for all of the collections, indexes, functions, and roles for your app. Such a script can be version controlled.

There are many
examples
in the
wild
of such setup scripts.

Hi @Sertge,
yes, had a similar behavior using WebUI, but the function looks ok, by inspecting it from the shell.
May ou check the code using the shell with:

Get(Function(<function_name>))

and see if the default is still there.
In any case, I opened an internal bug.

Luigi

1 Like

Hi, @ptpaterson, thanks, I will have a check on that
I usually put the functions on Fauna as sometimes these functions are large and I’d rather have them already on Fauna to reduce data transfer, but I guess it won’t do harm to do it locally

I think you misunderstand me. I mean to create a setup script that defines the UDFs that you will use.

i.e. Use CreateFunction in a setup script once, then your app can just call the function. If you need to update your function, then either delete and recreate it, or change the script to do an Update if it exists or else Create if it doesn’t. This is demonstrated in the links I sent.

const createOrUpdateFunction = params =>
  q.Let(
    {
      exists: q.Exists(q.Function(params.name)),
      function: q.If(
        q.Var('exists'),
        q.Update(q.Function(params.name), params),
        q.CreateFunction(params)
      )
    },
    {
      result: q.If(q.Var('exists'), 'updated', 'created'),
      function: q.Var('function')
    }
  )

Yep, I did misunderstand you.
What you’re doing here is awesome. I will start doing it that way.
Thanks a lot

Thank you very much!