Skip to content

Commit 89e7afc

Browse files
abnegateclaude
andcommitted
(fix): resolve Structure validator missing Float, TenantFilter alias check, and Document tenant type cast
- Add ColumnType::Float case to Structure validator switch (falls through to Double handling) - Pass actual collection name to TenantFilter so metadata check uses the real table name instead of the query alias - Remove int cast in Document::getTenant() to prevent strict comparison mismatches with Adapter::getTenant() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2444fe6 commit 89e7afc

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/Database/Adapter/SQL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ protected function newBuilder(string $table, string $alias = ''): SQLBuilder
28222822
'$permissions' => '_permissions',
28232823
]));
28242824
if ($this->sharedTables && $this->tenant !== null) {
2825-
$builder->addHook(new TenantFilter($this->tenant, Database::METADATA));
2825+
$builder->addHook(new TenantFilter($this->tenant, Database::METADATA, $table));
28262826
}
28272827

28282828
return $builder;

src/Database/Document.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,7 @@ public function getUpdatedAt(): ?string
241241
*/
242242
public function getTenant(): int|string|null
243243
{
244-
$tenant = $this->getAttribute('$tenant');
245-
246-
if (\is_numeric($tenant)) {
247-
return (int) $tenant;
248-
}
249-
250-
return $tenant;
244+
return $this->getAttribute('$tenant');
251245
}
252246

253247
/**

src/Database/Hook/TenantFilter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class TenantFilter implements Filter, JoinFilter
1717
/**
1818
* @param int|string $tenant The current tenant identifier
1919
* @param string $metadataCollection The metadata collection name; metadata tables allow NULL tenants
20+
* @param string $collection The actual collection/table name being queried (not the alias)
2021
*/
2122
public function __construct(
2223
private int|string $tenant,
23-
private string $metadataCollection = ''
24+
private string $metadataCollection = '',
25+
private string $collection = ''
2426
) {
2527
}
2628

@@ -30,7 +32,10 @@ public function filter(string $table): Condition
3032
// This avoids breaking subqueries where $table is a fully-qualified raw table name
3133
$prefix = (!\str_contains($table, '.') && !\str_contains($table, '`')) ? "{$table}." : '';
3234

33-
if (! empty($this->metadataCollection) && str_contains($table, $this->metadataCollection)) {
35+
// Check the actual collection name against the metadata collection, not the alias
36+
$name = $this->collection !== '' ? $this->collection : $table;
37+
38+
if (! empty($this->metadataCollection) && \str_contains($name, $this->metadataCollection)) {
3439
return new Condition("({$prefix}_tenant IN (?) OR {$prefix}_tenant IS NULL)", [$this->tenant]);
3540
}
3641

src/Database/Validator/Structure.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ protected function checkForInvalidAttributeValues(array $structure, array $keys)
375375
$validators[] = new Range($min, $max, ColumnType::Integer->value);
376376
break;
377377

378+
case ColumnType::Float:
378379
case ColumnType::Double:
379380
// We need both Float and Range because Range implicitly casts non-numeric values
380381
$validators[] = new FloatValidator();

0 commit comments

Comments
 (0)