Update query builder does not add 'false' value #7429

Open
opened 2026-01-22 15:51:37 +01:00 by admin · 0 comments
Owner

Originally created by @hxrriet02 on GitHub (Oct 9, 2024).

Bug Report

When trying to run a query builder update, trying to update a value to false with the set() method, an error occurs

Q A
BC Break no
Version 3.2.2

Summary

Same as the above, using an update/set query builder fails to run when using a false boolean

Current behavior

Throws an error due to the DQL not printing false as 0 or "false"

The error it throws

13:29:00 CRITICAL  [messenger] Error thrown while handling message App\Scheduler\Message\StatusUpdater. Removing from transport after 0 retries. Error: "Handling "App\Scheduler\Message\StatusUpdater" failed: [Syntax Error] line 0, col 43: Error: Expected Literal, got 'WHERE'" ["class" => "App\Scheduler\Message\StatusUpdater","message_id" => null,"retryCount" => 0,"error" => "Handling "App\Scheduler\Message\StatusUpdater" failed: [Syntax Error] line 0, col 43: Error: Expected Literal, got 'WHERE'","exception" => Symfony\Component\Messenger\Exception\HandlerFailedException^ { …}]

A dump of the DQL

^ "UPDATE App\Entity\Product n SET n.isOnline =  WHERE n.isOnline = true"

How to reproduce

Have a basic entity with a boolean field

    ....

    #[ORM\Column]
    private bool $isOnline = true;

    #[SerializedName('isOnline')]
    public function isOnline(): ?bool
    {
        return $this->isOnline;
    }

    #[SerializedName('isOnline')]
    public function setIsOnline(bool $isOnline): self
    {
        $this->isOnline = $isOnline;

        return $this;
    }

    ....

Run the following using the given repository

$this->repository->createQueryBuilder('n')
    ->update()
    ->set('n.isOnline', false)
    ->andWhere('n.isOnline = true')
    ->getQuery()
    ->execute();

Expected behavior

The boolean should type cast to either a integer 1/0 or a string 'true'/'false'

Originally created by @hxrriet02 on GitHub (Oct 9, 2024). ### Bug Report When trying to run a query builder update, trying to update a value to `false` with the set() method, an error occurs | Q | A |------------ | ------ | BC Break | no | Version | 3.2.2 #### Summary Same as the above, using an update/set query builder fails to run when using a false boolean #### Current behavior Throws an error due to the DQL not printing false as `0` or `"false"` The error it throws ``` 13:29:00 CRITICAL [messenger] Error thrown while handling message App\Scheduler\Message\StatusUpdater. Removing from transport after 0 retries. Error: "Handling "App\Scheduler\Message\StatusUpdater" failed: [Syntax Error] line 0, col 43: Error: Expected Literal, got 'WHERE'" ["class" => "App\Scheduler\Message\StatusUpdater","message_id" => null,"retryCount" => 0,"error" => "Handling "App\Scheduler\Message\StatusUpdater" failed: [Syntax Error] line 0, col 43: Error: Expected Literal, got 'WHERE'","exception" => Symfony\Component\Messenger\Exception\HandlerFailedException^ { …}] ``` A dump of the DQL ``` ^ "UPDATE App\Entity\Product n SET n.isOnline = WHERE n.isOnline = true" ``` #### How to reproduce Have a basic entity with a boolean field ```php .... #[ORM\Column] private bool $isOnline = true; #[SerializedName('isOnline')] public function isOnline(): ?bool { return $this->isOnline; } #[SerializedName('isOnline')] public function setIsOnline(bool $isOnline): self { $this->isOnline = $isOnline; return $this; } .... ``` Run the following using the given repository ```php $this->repository->createQueryBuilder('n') ->update() ->set('n.isOnline', false) ->andWhere('n.isOnline = true') ->getQuery() ->execute(); ``` #### Expected behavior The boolean should type cast to either a integer 1/0 or a string 'true'/'false'
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7429