mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
LockMode::NONE should not require transaction? #6926
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fliespl on GitHub (Feb 10, 2022).
Bug Report
Summary
Up for discussion if LockMode::NONE is really a transactional items.
Current behavior
Currently setting setLockMode(LockMode::NONE) does check for valid transaction, even though it doesn't do anything useful with most (all?) database servers.
Additionally, there is a check, which should be removed, since strict rules say that setLockMode should be int (phpstan returns errors when calling
setLockMode(null/false).How to reproduce
Expected behavior
Allow non-transaction usage.
@hubertnnn commented on GitHub (Apr 11, 2023):
I just wanted to add the same issue.
There is one extra thing that I would suggest.
After checking if
setLockMode(LockMode::NONE)actually does nothing I found thatHINT_LOCK_MODEthat is set by this function is used in exactly 3 places:SqlWalker.phpline 546$this->query->getHint(Query::HINT_LOCK_MODE) ?: LockMode::NONE;SqlWalker.phpline 970$this->query->getHint(Query::HINT_LOCK_MODE) ?: LockMode::NONEQuery.phpline 795Query::getLockMode()functionIn first two
LockMode::NONEis the default, in the third placenullis default.It also seems that
Query::getLockMode()is unused (at least on my project)So it seems that there is mostly no difference between not setting LockMode and setting it to
LockMode::NONEI would suggest not only removing the exception for transactions
but also improving consistency by returning
LockMode::NONEfromQuery::getLockMode()as default.edit:
Also until this is fixed a wourkaround would be to use
falseinstead ofLockMode::NONEsince its effects are the same, butfalsewill not throw an exception.