Skip to content

fix #103 Reset the entity manager when a process task has closed it - #131

Merged
njoubert-cleverage merged 1 commit into
mainfrom
103-closed-entity-manager
Oct 8, 2026
Merged

njoubert-cleverage merged 1 commit into
mainfrom
103-closed-entity-manager

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Fixes #103 (extension: entity manager closed by a process task; the cleared case was fixed by #104)

Changes

  • ProcessExecutionRepository::getManaged(): a closed entity manager is reset first (ManagerRegistry::resetManager()). The entity manager service is lazy: it is reset in place, so the services holding it (repository, DoctrineProcessHandler, process tasks) get an open one, as Symfony Messenger does after a Doctrine error. New optional constructor argument ?ManagerRegistry $registry = null (@doctrine in repository.yaml), no BC break.
  • DoctrineProcessHandler::flush(): without log to write, a closed entity manager is not flushed (it threw The EntityManager is closed. at the end of the process); it is reset when writing the next logs or saving the execution.
  • CHANGELOG: Current process execution inserted again or left started when a process task clears or closes the entity manager #103 entry completed (unreleased).

Tests

  • ProcessExecutionManagerEntityManagerTest::testEntityManagerClosedDuringTheProcess (entity manager of the test application): log, close(), log, end of the process: a single finish execution with its report, context and both logs; the entity manager service is open again (same instance).
  • DoctrineProcessHandlerTest: closed entity manager without records: no flush; open one: flushed as before.
  • Without the fix, the 2 new tests fail; with it, 295 tests OK. PHPStan, PHP-CS-Fixer, Rector OK.

Checked in process-bundle-demo (MySQL, doctrine-bundle 3.3, PHP 8.5, Symfony 7.4)

demo.ui.entity_manager_closed: log, DoctrineWriterTask writing an Author with a 300 characters last name (Data too long, entity manager closed by Doctrine), error_strategy: skip.

Execution Logs Command
Before started, no end date 0 Critical process failure: The EntityManager is closed.
After finish 9 (including the SQL error) executed successfully

With error_strategy: stop: a single failed execution with its 8 logs.

🤖 Generated with Claude Code

Doctrine closes the entity manager after an error during a flush: the current process execution could no longer be
saved nor its logs written (left started, "The EntityManager is closed."). ProcessExecutionRepository::getManaged()
resets a closed entity manager (ManagerRegistry::resetManager(), reset in place), DoctrineProcessHandler::flush() does
not flush a closed entity manager without logs to write.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage njoubert-cleverage added the bug Something isn't working label Oct 8, 2026
@njoubert-cleverage
njoubert-cleverage merged commit 7a31f01 into main Oct 8, 2026
24 checks passed
@njoubert-cleverage
njoubert-cleverage deleted the 103-closed-entity-manager branch October 8, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Current process execution inserted again or left started when a process task clears or closes the entity manager

1 participant