Fix audit schema generation for reserved-keyword table names on DBAL 4.3+#683
Open
gulaandrij wants to merge 1 commit into
Open
Fix audit schema generation for reserved-keyword table names on DBAL 4.3+#683gulaandrij wants to merge 1 commit into
gulaandrij wants to merge 1 commit into
Conversation
…4.3+
On doctrine/dbal >= 4.3 the audit table name was derived from getObjectName()->toString(), which renders a quoted identifier for reserved keywords (e.g. "user"). Concatenating it with the table prefix/suffix produced an unparseable name ("user"_audit), leaving the new table's name uninitialized and crashing with InvalidState: Object name has not been initialized. Use the unquoted identifier value instead, matching the pre-4.3 getName() behaviour.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Subject
On
doctrine/dbal >= 4.3, audit schema generation crashes withDoctrine\DBAL\Schema\Exception\InvalidState: Object name has not been initializedfor any audited entity whose table name is an SQL reserved keyword (and is therefore force-quoted).CreateSchemaListenerderives the audit table name from$entityTable->getObjectName()->toString(), which on DBAL >= 4.3 renders a quoted identifier for reserved keywords (e.g."user"). Concatenating it with the configured table prefix/suffix yields"user"_audit, which is not a parseable identifier: DBAL silently leaves the new table's name uninitialized and then throws fromgetObjectName()on the next access (here, while building the revision index name).The pre-4.3 code path used
Table::getName()(which returns the unquoted name), so it was not affected.This PR adds
DbalCompatibilityTrait::getUnquotedTableName(), which on DBAL >= 4.3 returns the raw unquoted identifier value (getObjectName()->getUnqualifiedName()->getValue(), prefixed with the qualifier when present) and otherwise falls back toTable::getName(). It is used at the three audit-table-name derivation sites (the entity table and the many-to-many join tables), restoring the historical behaviour.A regression test (
IssueReservedTableNameTest, with an entity mapped to a reserved`user`table) reproduces the crash before the fix and passes after it. The full test suite, PHPStan, PHP-CS-Fixer and Rector all pass ondoctrine/dbal4.4.3.I am targeting the
1.xbranch, because this is a backwards-compatible bug fix.Changelog