Uh oh!
There was an error while loading. Please reload this page.
Aliases for Dotted attribute not getting removed during decode in sql - #853
Conversation
…sts to ensure schema keys are exposed correctly
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes a bug in the SQL adapter's Confidence Score: 5/5Safe to merge — the fix is surgical, logically correct, and covered by a new e2e test. The one tricky invariant (that No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "refactor: streamline attribute filtering..." | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/e2e/Adapter/Scopes/DocumentTests.php (1)
6690-6743: Make teardown unconditional withtry/finallyIf any assertion fails before the last line, the collection is left behind. Wrapping the body in
try/finallykeeps test isolation deterministic.♻️ Proposed refactor
$database->createCollection($collectionId); - $this->assertTrue($database->createAttribute($collectionId, $attrId, Database::VAR_STRING, 128, false));-- // Optional attribute omitted: DB column is NULL — decode must not leave the SQL column name as a key.- $database->createDocument($collectionId, new Document([- '$id' => 'dev1',- '$permissions' => [- Permission::read(Role::any()),- Permission::update(Role::any()),- ],- ]));-- $doc = $database->getDocument($collectionId, 'dev1');- $this->assertSame('dev1', $doc->getId());- $this->assertNull($doc->getAttribute($attrId));- $this->assertArrayNotHasKey($filteredStorageKey, $doc->getAttributes());- $userKeys = array_keys($doc->getAttributes());- sort($userKeys);- $this->assertSame([$attrId], $userKeys);+ try {+ $this->assertTrue($database->createAttribute($collectionId, $attrId, Database::VAR_STRING, 128, false));++ // Optional attribute omitted: DB column is NULL — decode must not leave the SQL column name as a key.+ $database->createDocument($collectionId, new Document([+ '$id' => 'dev1',+ '$permissions' => [+ Permission::read(Role::any()),+ Permission::update(Role::any()),+ ],+ ]));++ $doc = $database->getDocument($collectionId, 'dev1');+ $this->assertSame('dev1', $doc->getId());+ $this->assertNull($doc->getAttribute($attrId));+ $this->assertArrayNotHasKey($filteredStorageKey, $doc->getAttributes());+ $userKeys = array_keys($doc->getAttributes());+ sort($userKeys);+ $this->assertSame([$attrId], $userKeys);- $updated = $database->updateDocument($collectionId, 'dev1', new Document([- $attrId => '1.0.0',- ]));- $this->assertSame('1.0.0', $updated->getAttribute($attrId));- $this->assertArrayNotHasKey($filteredStorageKey, $updated->getAttributes());- $userKeys = array_keys($updated->getAttributes());- sort($userKeys);- $this->assertSame([$attrId], $userKeys);+ $updated = $database->updateDocument($collectionId, 'dev1', new Document([+ $attrId => '1.0.0',+ ]));+ $this->assertSame('1.0.0', $updated->getAttribute($attrId));+ $this->assertArrayNotHasKey($filteredStorageKey, $updated->getAttributes());+ $userKeys = array_keys($updated->getAttributes());+ sort($userKeys);+ $this->assertSame([$attrId], $userKeys);- $doc = $database->getDocument($collectionId, 'dev1');- $this->assertSame('1.0.0', $doc->getAttribute($attrId));- $this->assertArrayNotHasKey($filteredStorageKey, $doc->getAttributes());- $userKeys = array_keys($doc->getAttributes());- sort($userKeys);- $this->assertSame([$attrId], $userKeys);+ $doc = $database->getDocument($collectionId, 'dev1');+ $this->assertSame('1.0.0', $doc->getAttribute($attrId));+ $this->assertArrayNotHasKey($filteredStorageKey, $doc->getAttributes());+ $userKeys = array_keys($doc->getAttributes());+ sort($userKeys);+ $this->assertSame([$attrId], $userKeys);- $updated = $database->updateDocument($collectionId, 'dev1', new Document([- $attrId => '2.0.0',- ]));- $this->assertSame('2.0.0', $updated->getAttribute($attrId));- $this->assertArrayNotHasKey($filteredStorageKey, $updated->getAttributes());- $userKeys = array_keys($updated->getAttributes());- sort($userKeys);- $this->assertSame([$attrId], $userKeys);+ $updated = $database->updateDocument($collectionId, 'dev1', new Document([+ $attrId => '2.0.0',+ ]));+ $this->assertSame('2.0.0', $updated->getAttribute($attrId));+ $this->assertArrayNotHasKey($filteredStorageKey, $updated->getAttributes());+ $userKeys = array_keys($updated->getAttributes());+ sort($userKeys);+ $this->assertSame([$attrId], $userKeys);- $doc = $database->getDocument($collectionId, 'dev1');- $this->assertSame('2.0.0', $doc->getAttribute($attrId));- $this->assertArrayNotHasKey($filteredStorageKey, $doc->getAttributes());- $userKeys = array_keys($doc->getAttributes());- sort($userKeys);- $this->assertSame([$attrId], $userKeys);-- $database->deleteCollection($collectionId);+ $doc = $database->getDocument($collectionId, 'dev1');+ $this->assertSame('2.0.0', $doc->getAttribute($attrId));+ $this->assertArrayNotHasKey($filteredStorageKey, $doc->getAttributes());+ $userKeys = array_keys($doc->getAttributes());+ sort($userKeys);+ $this->assertSame([$attrId], $userKeys);+ } finally {+ $database->deleteCollection($collectionId);+ }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/e2e/Adapter/Scopes/DocumentTests.php` around lines 6690 - 6743, Test teardown currently runs only at the end so if an assertion fails the created collection remains; wrap the test body that runs between $database->createCollection(...) and $database->deleteCollection($collectionId) in a try/finally and move the $database->deleteCollection($collectionId) call into the finally block to guarantee cleanup; locate the sequence using the calls to $database->createCollection, $database->createAttribute, multiple $database->getDocument/$database->updateDocument, and $database->deleteCollection and ensure the finally still runs even if earlier assertions fail (optionally check that $collectionId is set before calling deleteCollection).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/e2e/Adapter/Scopes/DocumentTests.php`:
- Around line 6690-6743: Test teardown currently runs only at the end so if an
assertion fails the created collection remains; wrap the test body that runs
between $database->createCollection(...) and
$database->deleteCollection($collectionId) in a try/finally and move the
$database->deleteCollection($collectionId) call into the finally block to
guarantee cleanup; locate the sequence using the calls to
$database->createCollection, $database->createAttribute, multiple
$database->getDocument/$database->updateDocument, and
$database->deleteCollection and ensure the finally still runs even if earlier
assertions fail (optionally check that $collectionId is set before calling
deleteCollection).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cff49971-6174-46ba-bebf-9e05ce68c9b3
📒 Files selected for processing (2)
src/Database/Database.phptests/e2e/Adapter/Scopes/DocumentTests.php
Uh oh!
There was an error while loading. Please reload this page.
'a.b' getting stored as 'ab' in sql
during decode we are setitng the 'a.b' but not removing the 'ab' -> structure validation error during update
Summary by CodeRabbit
Bug Fixes
Tests