When checking for open task items in a local task, the query refers to task_item->id() instead of task->id().

Any correct result in the past has been pure coincidence.

      $unclosed_tasks = \Drupal::entityQuery('tmgmt_local_task_item')
        ->condition('tltid', $task_item->id())
        ->condition('status', LocalTaskItemInterface::STATUS_CLOSED, '<>')
        ->count()
        ->execute();
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cgalli created an issue. See original summary.

cgalli’s picture

Title: Query for open unclosed task item using wrong entity id » Query for open unclosed task items using wrong entity id
cgalli’s picture

Status: Active » Needs review
FileSize
680 bytes

Correction patch

Berdir’s picture

I don't think that's enough, the condition is still on the task item id?

Will also need tests.

cgalli’s picture

hmm. it takes the task from task_item and then the id of the task...

$task_item->getTask() returns the task to which the item belongs.

cgalli’s picture

yes, I see...

will look at tests

miro_dietiker’s picture

@Berdir isn't tltid the task ID? I think it is...

Berdir’s picture

right, the other is iid or so, I hate those ids :)

Berdir’s picture

However, as mentioned, the whole code block is the in the wrong place, just like job_item/job, this second part should live in a hook that listens on task items being closed. If there is ever another scenario where a task item can be closed then it wouldn't work.

cgalli’s picture

With the patch, the query gets all task items that have the same task (tltid) and are not yet closed, then counts them. If none left, then the complete task can be closed. Correct?

The test checks that the task is not closed after saving only the first task item as completed. I am unsure if that is sufficient.

Status: Needs review » Needs work

The last submitted patch, 10: unclosed_query_2772807_7.patch, failed testing.

cgalli’s picture

Correct Syntax for the test....

cgalli’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Submitting a test-only patch, hopefully see it fail.

miro_dietiker’s picture

Status: Needs review » Needs work

A test-only patch needs to fail. otherwise it doesn't check what it's supposed to check: the current bug!

Plus yeah, the Berdir refactoring. :-)

Berdir’s picture

likely just needs to clear static cache and re-load the task to see the change.

If we don't already, we should also confirm that the task is closed at the end, but I hope we do that already

cgalli’s picture

It depends.

The bug is such that it does not occur in all circumstances (see miros and christophes manual testing on 26 Jul), so the test will not always fail. But the test will make sure that the bug does not lead to false results.

IMHO there is no other possible test as the bug falsely closes the task without touching the items.

As berdir said, testing the task in the end for being closed. This is covered by:

    \Drupal::entityTypeManager()->getStorage('tmgmt_local_task_item')->resetCache();
    $task = tmgmt_local_task_load($task->id());
    $this->assertTrue($task->isClosed());
    list($first_task_item, $second_task_item) = array_values($task->getItems());
    $this->assertTrue($first_task_item->isClosed());
    $this->assertTrue($second_task_item->isClosed());