Repository navigation
Conversation
Adds ADR-0005, decided while triaging #16.
DoctrineOrmBasedMetadataStore::store() flushed the application's entity manager, so it also wrote every change the application made to its managed entities without flushing it, e.g. the half-done changes of a controller that threw. And when a concurrent request had inserted the client's row first, the failed INSERT closed the application's entity manager. store() now writes through a new EntityManager on the connection, Configuration and EventManager of the application's, and drops it after the flush. Its unit of work only holds the client's row, and a failed INSERT closes only that entity manager. load() still reads through the application's entity manager. Closes #16
This was referenced Nov 30, 2026
Member
Author
|
Superseded by #40. Writing through a new entity manager per write kept the ORM where a key/value store doesn't need it: an entity manager built outside DoctrineBundle, the application's flush listeners on every metadata write, a SELECT before every write, and reliance on behaviour ORM 3.7 deprecated. #40 reads and writes the table with DBAL instead (see #39 and ADR-0005 there). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16.
Summary
DoctrineOrmBasedMetadataStore::store()writes changed metadata through a newEntityManageron the connection,ConfigurationandEventManagerof the application's entity manager, instead of flushing the application's.store(client) if metadata hasn't changed return # no entity manager, no query - manager = application's entity manager + manager = new EntityManager(application's connection, configuration, event manager) entity = manager.find(client id) ?? persist a new entity entity.setMetadata(metadata) manager.flush() # a unique violation from a concurrent INSERT is ignoredBefore, that flush also wrote every change the application made to its managed entities without flushing it, e.g. the half-done changes of a controller that threw, since
kernel.finish_requestruns then too. And when a concurrent request had inserted the client's row first, the failed INSERT closed the application's entity manager for the rest of the request. Now the store's unit of work holds only the client's row, and a failed INSERT closes only the store's entity manager. The concurrent row still wins.load()still reads through the application's entity manager.Sharing the
ConfigurationandEventManagerkeeps a custommetadata_class's mapping, constructor, lifecycle callbacks and entity listeners, and the application's listeners, running as before. ORM 3.7 declaresgetEventManager()as returningEventManagerInterface, but its constructor takes onlyEventManager, so an inline@varnarrows it: ORM 3.x still returns anEventManager, and the constructor's native type enforces it.ADR-0005 records the decision and the rejected options: writing with DBAL, an entity manager the application configures, and one private entity manager. README, UPGRADE-2.0.md and CLAUDE.md describe the new write path.
src/now uses the ORM's classes directly, socomposer-dependency-analyser.phpdrops itsdoctrine/ormignore.Evidence
MetadataTest::it_does_not_store_changes_that_the_application_did_not_flushfails in all three metadata class environments. Another client's row, changed in memory by the request but never flushed, is stored as{"changed":"in memory only"}.After: it passes. The other client's row keeps
{"foo":"bar"}.it_keeps_the_row_of_a_concurrent_request_that_stored_it_first, with the newisOpen()assertion, fails: "The failed write closed the entity manager of the application".After: it passes.
new EntityManager(Connection, Configuration, ?EventManager)is public there, and all 154 tests pass.Merge Danger
Door: two-way
A revert brings back the flush of the application's entity manager. The table, its columns and the stored rows don't change.
Blast Radius: Doctrine listeners
onFlush,postFlush, …) also see the store's flush, with the store's entity manager in their event arguments.load().load()found isn't refreshed after the write.