Skip to content

IBX-11842: Fixed SiteAccessAwareEntityManager::find() ignoring lock mode and lock version#777

Open
alongosz wants to merge 3 commits into
4.6from
ibx-11842-siteaccess-aware-em-find-lock-mode
Open

IBX-11842: Fixed SiteAccessAwareEntityManager::find() ignoring lock mode and lock version#777
alongosz wants to merge 3 commits into
4.6from
ibx-11842-siteaccess-aware-em-find-lock-mode

Conversation

@alongosz

@alongosz alongosz commented Jul 8, 2026

Copy link
Copy Markdown
Member
🎫 Issue IBX-11842

Related PRs:

  • ibexa/taxonomy#423

Description:

Ibexa\Core\Persistence\Doctrine\SiteAccessAwareEntityManager::find() declared only ($className, $id), silently dropping the $lockMode and $lockVersion parameters of Doctrine's EntityManager::find(). Any caller requesting a pessimistic lock, e.g. $em->find(TaxonomyEntry::class, $id, LockMode::PESSIMISTIC_WRITE), got no lock and no error — the intended SELECT … FOR UPDATE was never executed. Discovered while investigating IBX-11842 (taxonomy nested-set insert deadlocks), where the pessimistic lock was silently skipped.

The method now accepts and forwards both parameters to the wrapped entity manager, matching Doctrine\ORM\Decorator\EntityManagerDecorator::find().

The rest of the decorator was audited against the interface: no other method narrows its signature (refresh() already forwards $lockMode, lock() forwards all arguments).

A scoped PHPStan ignoreErrors entry was added, because Doctrine\Persistence\ObjectManager::find() declares only two parameters in both persistence v2 and v3 — the same false-positive class as the existing clear() entry in phpstan-baseline-doctrine-persistence-v3.neon.

For QA:

Covered by unit tests. Functional check: according to IBX-11842 steps, together with ibexa/taxonomy#423 PR.

Regression run:

* @template T of object
*
* @param class-string<T> $className
* @param int|null $lockMode one of the \Doctrine\DBAL\LockMode::* constants or null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve phpstan analisys you can use @param \Doctrine\DBAL\LockMode::*|null instead 😉
https://phpstan.org/writing-php-code/phpdoc-types#literals-and-constants

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve phpstan analisys you can use @param \Doctrine\DBAL\LockMode::*|null instead 😉 https://phpstan.org/writing-php-code/phpdoc-types#literals-and-constants

Good catch, must've disappeared when I was testing different version of doctrine persistence.
Actually, this is PHPStan-specific syntax, so I need to use here phpstan-param. Made redundant param so PHPStorm analysis doesn't false-negative mark this doc block as incomplete (in some places we did sth similar, but mostly for phpDocumentor).

Aligned also method signature with doctrine persistence v3. Looks like it passes on both v2 and v2.
8ee1150

alongosz and others added 3 commits July 14, 2026 11:16
The decorator narrowed EntityManagerInterface::find() to two
parameters, so callers requesting a pessimistic or optimistic lock
(e.g. LockMode::PESSIMISTIC_WRITE) silently got no lock and no error.
The arguments are now forwarded to the wrapped entity manager, the
same way Doctrine\ORM\Decorator\EntityManagerDecorator does.

Added a scoped PHPStan ignore, as ObjectManager::find() declares only
two parameters in both doctrine/persistence v2 and v3.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Made PHPStan $lockMode parameter type hint more specific.
* Changed PHPStan specific syntax hints to be `@phpstan-param`
* Added fallback `@param` syntax to satisfy signature completeness analysis
@alongosz
alongosz force-pushed the ibx-11842-siteaccess-aware-em-find-lock-mode branch from dde76aa to 8ee1150 Compare July 14, 2026 09:17
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants