Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hxrriet02 opened this issue Oct 9, 2024 · 0 comments
Open

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

hxrriet02 opened this issue Oct 9, 2024 · 0 comments

Comments

@hxrriet02
Copy link

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant