Tasks not linked to a project

Background: I tend to create TODO’s in my journal pages, but I’m having a hard time getting back to them, so they end up piling up over time.
To try to solve this, I want to split my work into “projects”, which are pages with the type:: project set. On the project pages, I have a query that lists all tasks that are linked to that project.

What I would like to have is a ‘catch all’ query that finds all tasks that have NOT been assigned to a project, to make sure I don’t loose track of tasks outside of projects.

So far I can query all TODO’s, and I can query all “project” pages, but I’m not sure how to combine them.
I found this question which seems close to what I want to do, and I get some of the tasks for projects with the below code, but not all of them.

#+BEGIN_QUERY
  {
     :query [
       :find (pull ?b [*])
       :where
        (task ?b #{"TODO"})
        [?b :block/refs ?ref]
        (page-property ?ref :type "project")
      ]
  }
#+END_QUERY

Also, any advice on how to debug queries would be welcome, I find it quite cumbersome to work on queries in logseq itself, and if I open my page in an external editor the two tools start overwriting each other.

Never open the same *.md file from different clients or even two logseq instances in different devices. I am not a Logseq Sync beta user, but I think that’s the only available way to run them in parallel safely without ruin it.

I do so.e VS Code edit while logseq it’s open, but because I forget. Whenever I can, I close it.

1 Like

Welcome.

  • Are these three questions?
    • catch non-assigned tasks
      • topic’s title
    • catch all tasks that are linked to a project
      • provided code
    • debugging queries
      • check this (expand the block)
  • Please provide example blocks for each case that you want to be covered.

Thanks for the link to the debugging options!

In the end, I want to have a query for non-assigned tasks. My plan to do that is to first query all tasks that are assigned to a project, and use that to negate the set of all tasks.

Description of example blocks:
First, there are pages for “projects”, that have the type::project property set, for example the page “Reduce waste”, but there are others as well.
Next, on my journal page I make TODO’s as normal.

TODO Set all printers to print two sided by default [[Reduce waste]]
TODO Some other task not related to any project

I want to write a query that will get me all tasks not related to any projects.

  • This is to get all tasks linked to a project:
    #+BEGIN_QUERY
      {
        :query [
          :find (pull ?b [*])
          :where
            [?b :block/marker]
            [?b :block/refs ?ref]
            (page-property ?ref :type "project")
        ]
      }
    #+END_QUERY
    
  • This is for those not linked to a project:
    #+BEGIN_QUERY
      {
        :query [
          :find (pull ?b [*])
          :where
            [?b :block/marker]
            (not
              [?b :block/refs ?ref]
              (page-property ?ref :type "project")
            )
        ]
      }
    #+END_QUERY
    
1 Like

Thanks, your query does show all tasks that are/aren’t linked to a “project”, even if the task is not specified on the project page!

I’ve tried to modify your query to only contain open tasks (TODO), but for some reason when I add my modification I end up with TODO’s which are not in projects. Can you tell me where I’m going wrong?

I’ve added [(contains? #{"TODO"} ?marker)] to the query you gave:

#+BEGIN_QUERY
  {
    :query [
      :find (pull ?b [*])
      :where
        [?b :block/marker ?marker]
        [(contains? #{"TODO"} ?marker)]
        (not
          [?b :block/refs ?ref]
          (page-property ?ref :type "project")
        )
    ]
  }
#+END_QUERY

You added the modification [(contains? #{"TODO"} ?marker)] to the query for the tasks that are not in projects (notice the not in it). Should instead add it to the previous query (the one without the not in it).

I’m sorry for the confusion, I made a mistake copy/pasting the query.

This query works, and only returns TODO’s that are linked to a project.

#+BEGIN_QUERY
  {
    :query [
      :find (pull ?b [*])
      :where
        [?b :block/marker ?marker]
        [?b :block/refs ?ref]
        [(contains? #{"TODO"} ?marker)]
        (page-property ?ref :type "project")
    ]
  }
#+END_QUERY

However, I’ve found there is a mistake in the query for blocks that are not linked to projects:

#+BEGIN_QUERY
  {
    :query [
      :find (pull ?b [*])
      :where
        [?b :block/marker]
        (not
          [?b :block/refs ?ref]
          (page-property ?ref :type "project")
        )
    ]
  }
#+END_QUERY

For some reason this query still returns tasks which are liked to projects. This appears to only happen when the task is not linked directly to the project key, but one of the parents of the task is linked to the project. Is there a specific query that takes this inheritance into account?

Try using :block/path-refs in place of :block/refs . Otherwise, provide example blocks for us to test the query against.

The final query to get all open tasks (TODO) not linked to a page with the type::project tag is this, thanks to @mentaloid

#+BEGIN_QUERY
{
  :query [
    :find (pull ?b [*])
    :where
      [?b :block/marker ?marker]
      [(contains? #{"TODO"} ?marker)]
      (not
        [?b :block/path-refs ?ref]
        (page-property ?ref :type "project")
      )
  ]
}
#+END_QUERY