Skip to content

Commit 53096f2

Browse files
authored
fix: preserve cached table list shape (#10179)
* fix: preserve cached table list shape * docs: add changelog entry for cached table list fix Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com> --------- Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent bca4ad9 commit 53096f2

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

system/Database/BaseConnection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,9 +1684,11 @@ protected function getDriverFunctionPrefix(): string
16841684
public function listTables(bool $constrainByPrefix = false)
16851685
{
16861686
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) {
1687-
return $constrainByPrefix
1687+
$tables = $constrainByPrefix
16881688
? preg_grep("/^{$this->DBPrefix}/", $this->dataCache['table_names'])
16891689
: $this->dataCache['table_names'];
1690+
1691+
return array_values($tables);
16901692
}
16911693

16921694
$sql = $this->_listTables($constrainByPrefix);

tests/system/Database/Live/MetadataTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function dropExtraneousTable(): void
7878
$oldPrefix = $this->db->getPrefix();
7979
$this->db->setPrefix('tmp_');
8080

81-
Database::forge($this->DBGroup)->dropTable('widgets');
81+
Database::forge($this->DBGroup)->dropTable('widgets', true);
8282

8383
$this->db->setPrefix($oldPrefix);
8484
}
@@ -139,4 +139,22 @@ public function testListTablesConstrainedByExtraneousPrefixReturnsOnlyTheExtrane
139139
$this->dropExtraneousTable();
140140
}
141141
}
142+
143+
public function testListTablesReturnsListAfterCachedTableIsDropped(): void
144+
{
145+
try {
146+
$this->createExtraneousTable();
147+
148+
$tables = $this->db->listTables();
149+
$this->assertSame(array_values($tables), $tables);
150+
151+
$this->dropExtraneousTable();
152+
153+
$tables = $this->db->listTables();
154+
$this->assertSame(array_values($tables), $tables);
155+
$this->assertNotContains('tmp_widgets', $tables);
156+
} finally {
157+
$this->dropExtraneousTable();
158+
}
159+
}
142160
}

user_guide_src/source/changelogs/v4.7.3.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ Bugs Fixed
4141
- **CLI:** Fixed a bug where ``CLI::generateDimensions()`` leaked ``tput`` error output (``tput: No value for $TERM and no -T specified``) to stderr when the ``stty`` fallback was reached and the ``TERM`` environment variable was not set.
4242
- **Commands:** Fixed a bug in the ``env`` command where passing options only would cause the command to throw a ``TypeError`` instead of showing the current environment.
4343
- **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown.
44-
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
44+
- **Database:** Fixed a bug where ``BaseConnection::listTables()`` could return a sparse array when using cached table names after a table was dropped.
4545
- **Database:** Fixed a bug where the PostgreSQL driver's ``increment()`` and ``decrement()`` methods were not working for numeric columns.
46+
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
4647
- **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets.
4748
- **Toolbar:** Fixed a bug where the Logs collector raised an undefined property error when using a third-party PSR-3 logger.
4849
- **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator.

0 commit comments

Comments
 (0)