-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Method getLockVersion of ModelManager does not return correct value #1764
Comments
I never used this feature, but what is wrong with the current implementation: SonataDoctrineORMAdminBundle/src/Model/ModelManager.php Lines 122 to 131 in 258ba41
? |
Can this be conceptual problem ? Accessing version field via reflection bypasses Doctrine proxy classes and does not trigger initiation. What was the point behind reflection anyway? |
No idea, it was implemented long time ago #478 Do you have another implementation in mind ? |
Another implementation in my mind is accessing version field directly. Of course, we cannot call getter like bellow, and we should access via some property accessor probably public function getLockVersion(object $object)
{
$metadata = $this->getMetadata($object::class);
if (!$metadata->isVersioned) {
return null;
}
return $object->{'get' . ucfirst($metadata->versionField)}(); // some property accessor should be used here
} And from another point of view, I am not currently sure why this issue is happening only for some versioned entities. Meaning, some my entities are not initialized when configureFormFields() takes place and some are. When they are initialized, everything works flawlessly |
IMHO, I think get locking version should be transparent and shoudn't bypass Doctrine proxy classes, I currently see no reason for this. |
You can try a PR with PropertyAccessor. But maybe Doctrine has a better way to do this, since lock is a "doctrine feature" |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Environment
Sonata packages
show
Symfony packages
show
PHP version
Subject
When editing entity via form with version property (and optimistic locking enabled), false-positive flash message "Another user has modifed item ..." occurs.
After small investigation, I noticed:
Quicky and dirty workaround is to call getter of your version field to begin of configureFormMapper() method to initialize entity from database:
In situations when entity is for some reason already initialized in method configureFormFields(), of course, this is not the case.
Minimal repository with the bug
Steps to reproduce
Expected results
Actual results
The text was updated successfully, but these errors were encountered: