State property not being updated on flush() #7066

Closed
opened 2026-01-22 15:44:03 +01:00 by admin · 0 comments
Owner

Originally created by @nathansalter on GitHub (Nov 1, 2022).

Bug Report

Q A
BC Break no
Version 2.9.3

Summary

Basically, we've got a lot of entities in the DB, but sometimes the state property on some of these entities doesn't get updated on flush(). This has ended up with this code snippet being used in our application:

    /**
     * You might be wondering why there's a method here which is circumventing Doctrine's persist/flush
     * methods. For some reason at this point, Doctrine refuses to update the state on the booking even though
     * it has changed. Not sure why, so we have to get around it by manually performing the DB queries.
     */
    public static function forceState(ManagerRegistry $doctrine, Order $order): void
    {
        /** @var Connection $connection */
        $connection = $doctrine->getConnection('account');
        $statement = $connection->prepare('UPDATE booking SET state = :state WHERE id = :booking_id');
        foreach ($order->getBookings() as $booking) {
            $statement->execute([
                ':booking_id' => $booking->getId(),
                ':state' => $booking->getState()
            ]);
        }
    }

This doesn't happen all the time, and only happens on the state property, not any of the others. I'm assuming that somewhere, the changeset is being recalculated before the changes are persisted, but I can't find any of our listeners which are doing this.

Current behavior

State property is not updated.

How to reproduce

This is why I've waited so long to report this, I've been completely unable to replicate this issue, printing out lines and running debug, but every time I've tried this it's worked. The problem is consistent, and happens when only the state is updated, rather than any other properties. Any clues as to what to look for or how to track down what's happening here would be really appreciated.

Expected behavior

State property is updated.

Originally created by @nathansalter on GitHub (Nov 1, 2022). ### Bug Report | Q | A |------------ | ------ | BC Break | no | Version | 2.9.3 #### Summary Basically, we've got a lot of entities in the DB, but *sometimes* the `state` property on some of these entities doesn't get updated on `flush()`. This has ended up with this code snippet being used in our application: ```php /** * You might be wondering why there's a method here which is circumventing Doctrine's persist/flush * methods. For some reason at this point, Doctrine refuses to update the state on the booking even though * it has changed. Not sure why, so we have to get around it by manually performing the DB queries. */ public static function forceState(ManagerRegistry $doctrine, Order $order): void { /** @var Connection $connection */ $connection = $doctrine->getConnection('account'); $statement = $connection->prepare('UPDATE booking SET state = :state WHERE id = :booking_id'); foreach ($order->getBookings() as $booking) { $statement->execute([ ':booking_id' => $booking->getId(), ':state' => $booking->getState() ]); } } ``` This doesn't happen all the time, and only happens on the state property, not any of the others. I'm assuming that somewhere, the changeset is being recalculated before the changes are persisted, but I can't find any of our listeners which are doing this. #### Current behavior State property is not updated. #### How to reproduce This is why I've waited so long to report this, I've been completely unable to replicate this issue, printing out lines and running debug, but every time I've tried this it's worked. The problem is consistent, and happens when only the state is updated, rather than any other properties. Any clues as to what to look for or how to track down what's happening here would be really appreciated. #### Expected behavior State property is updated.
admin closed this issue 2026-01-22 15:44:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7066