Collection does not support query

Hi @zef !

I’ve recently updated to the edge version and surprisingly this thing stopped working.

I had this function that returns a list of tasks from specific namespace (hence namePrefix):

function tasks.list()
  return query [[
    from index.tag "task"
    where name.startsWith(namePrefix)
  ]]
end

And then I have this one, that uses that function to further narrow down the tasks I want to see on some page:

${query[[
  from tasks.list()
  select "[[" .. name .. "]]"
  where status == "completed"
    and journal.withinThisWeek(utils.getLastPageNamePart(), doneDate)
  order by doneDate
]] or "You've done nothing!"}

I’m not sure which version I had before, so this could’ve been changed even months back.

Thing is - I found this kind of composability quite useful. My question is - should this work or does it have some obvious flaw that I can’t see right now? Is there any alternative approach to have this working?

Stopped working means you’re getting an error, or no results?

This should still work, beside the bug in name.startsWith(namePrefix), which should be name:startsWith(namePrefix) but that should never have worked?

Note that recently we made the Lua interpreter more strict (closer to the the spec) and this is highlighting some latent bugs in people’s code. Most commonly, previously the + could be used to concatenate strings (which is not Lua semantics), whereas now it no longer can (you need to use ..). Perhaps something like that is happening elsewhere in your code?

@zef I’m very surprised that before the name.startsWith did work for some reason (or didn’t and I didn’t notice :D)

I actually spent some time with my code and the reason for the error was that tasks.list() returned an empty table.

I’ve prepared two minimal examples that showcase this, because I think this is something that needs fixing within Silverbullet itself:

${query[[from {}]]}  -- error: "Cllection does not support query"
${query[[from {{name="Foo"}}]]}  -- this works just fine

So the problem surfaces when querying an empty table.

I fixed this some days ago on the edge builds I’m pretty sure, because I ran into the same edge case. have you recently updated?

I can confirm there is no error just (empty table) in latest edge build:

Updated just now and it works correctly. Thank you!

1 Like