[PR #8508] Proposed fix for #8499 #11035

Closed
opened 2026-01-22 16:09:30 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/8508

State: closed
Merged: Yes


Changed lock function to compare timestamps instead of DateTimeInterface objects directly.

When using optimistic lock with DateTimeInterface based version field a bug appears due to the use of the === operator for comparing the lock version and the entity version. This comparison always resolves to false because the === operator when comparing objects is only true when both sides are the exact same instance of the object.

To fix the issue I have decided to compare timestamps instead the DateTimeInterface based objects directly, calling getTimestamp() method and doing a strict comparison.

Modified OptimisticLockException to use DateTimeInterface instead of DateTime class.

Added test suite to cover case.

Fixes #8499

**Original Pull Request:** https://github.com/doctrine/orm/pull/8508 **State:** closed **Merged:** Yes --- Changed lock function to compare timestamps instead of DateTimeInterface objects directly. When using optimistic lock with DateTimeInterface based version field a bug appears due to the use of the === operator for comparing the lock version and the entity version. This comparison always resolves to false because the === operator when comparing objects is only true when both sides are the exact same instance of the object. To fix the issue I have decided to compare timestamps instead the DateTimeInterface based objects directly, calling getTimestamp() method and doing a strict comparison. Modified OptimisticLockException to use DateTimeInterface instead of DateTime class. Added test suite to cover case. Fixes #8499
admin added the pull-request label 2026-01-22 16:09:30 +01:00
admin closed this issue 2026-01-22 16:09:31 +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#11035