Skip to content

fix: respect query value limits when loading relationships - #964

Open
HarshMN2345 wants to merge 1 commit into
mainfrom
codex/fix-relationship-query-value-limit
Open

fix: respect query value limits when loading relationships#964
HarshMN2345 wants to merge 1 commit into
mainfrom
codex/fix-relationship-query-value-limit

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 10, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Relationship loading batches up to 5,000 IDs even when the connection permits fewer query values. A document with 501 related IDs therefore fails to load with a 500-value limit.

Cap all five relationship query batches at the configured limit, using the existing inline chunking pattern. The 5,000-value ceiling and validation of caller-supplied queries remain unchanged.

Test Plan

  • Nine regression cases cover all relationship types in both directions, plus a single parent exceeding the limit. Explicit oversized queries remain rejected.
  • PostgreSQL, SQLite, and shared-table PostgreSQL: 27 focused tests / 129 assertions passed. All nine PostgreSQL cases fail without the fix.
  • All 21 reported CI checks passed, including the full adapter suites, unit tests, lint, and CodeQL.

Appwrite adoption requires a library release and dependency update. The HTTP regression is appwrite/appwrite#13610.

Summary by CodeRabbit

  • Bug Fixes

    • Relationship lookups now respect the configured maximum number of query values per request.
    • Related records can be fetched reliably without exceeding query value limits, including many-to-many relationships.
  • Tests

    • Added coverage for relationship queries under configured value limits.
    • Confirmed that explicit queries exceeding the limit continue to return the expected error.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 4e300ccd-fbf0-4104-b3dd-77424e3a8667

📥 Commits

Reviewing files that changed from the base of the PR and between 5592a23 and acdefcb.

📒 Files selected for processing (2)
  • src/Database/Database.php
  • tests/e2e/Adapter/Scopes/RelationshipTests.php

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Relationship population batches now cap ID lookup chunks at maxQueryValues. End-to-end tests cover all relationship types, many-to-many related-document lookups, explicit oversized queries, cleanup, and configuration restoration.

Changes

Relationship query limits

Layer / File(s) Summary
Relationship batch limits
src/Database/Database.php
All five relationship population lookup paths cap array_chunk sizes at the configured maxQueryValues value.
Relationship limit validation
tests/e2e/Adapter/Scopes/RelationshipTests.php
Tests cover relationship types, limited lookups, many-to-many related documents, oversized query exceptions, cleanup, and limit restoration.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: abnegate

Merge Risk: ⚪ Minimal · up to acdef

Relationship loading now respects configured query-value limits without changing oversized explicit-query behavior. Coverage spans the supported relationship paths, so the change is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: relationship loading now respects configured query value limits.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-relationship-query-value-limit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@HarshMN2345
HarshMN2345 marked this pull request as ready for review September 10, 2026 13:41
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The production fix appears sound, but the implementation-coupled test assertion must be replaced to satisfy the repository’s explicit testing requirement before merging.

Fix All in Claude CodeFindings

  1. P2 Brittle Exception Assertion
Fix with agent prompt
### Issue 1
tests/e2e/Adapter/Scopes/RelationshipTests.php:109
This assertion copies the validator’s exact wording and the configured value limit instead of testing only the observable behavior that an oversized query is rejected. That violates the repository requirement against implementation-coupled tests and would make harmless message changes break this end-to-end test. This requirement must be satisfied before merging.

```suggestion
                $this->assertInstanceOf(QueryException::class, $exception);
```

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

  • Applies bounded chunking to all one-to-one, one-to-many, many-to-one, and many-to-many loading paths.
  • Adds end-to-end coverage for both relationship directions and for a parent containing more related IDs than one query permits.
  • Keeps caller-supplied oversized queries subject to normal validation.

Reviews (1) · Last reviewed commit: "fix: respect configured query values whe..."

$database->find($children, [Query::equal('$id', ['child1', 'child2', 'child3'])]);
$this->fail('Explicit queries must still respect the configured value limit.');
} catch (QueryException $exception) {
$this->assertSame('Invalid query: Query on attribute has greater than 2 values: $id', $exception->getMessage());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Brittle Exception Assertion

This assertion copies the validator’s exact wording and the configured value limit instead of testing only the observable behavior that an oversized query is rejected. That violates the repository requirement against implementation-coupled tests and would make harmless message changes break this end-to-end test. This requirement must be satisfied before merging.

Suggested change
$this->assertSame('Invalid query: Query on attribute has greater than 2 values: $id', $exception->getMessage());
$this->assertInstanceOf(QueryException::class, $exception);

Context Used: Call out and harshly judge implementation-coupled ... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Adapter/Scopes/RelationshipTests.php
Line: 109

Comment:
**Brittle Exception Assertion**

This assertion copies the validator’s exact wording and the configured value limit instead of testing only the observable behavior that an oversized query is rejected. That violates the repository requirement against implementation-coupled tests and would make harmless message changes break this end-to-end test. This requirement must be satisfied before merging.

```suggestion
                $this->assertInstanceOf(QueryException::class, $exception);
```

**Context Used:** Call out and harshly judge implementation-coupled ... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

Comment thread src/Database/Database.php

// Process in chunks to avoid exceeding query value limits
foreach (\array_chunk($uniqueRelatedIds, self::RELATION_QUERY_CHUNK_SIZE) as $chunk) {
foreach (\array_chunk($uniqueRelatedIds, \max(1, \min(self::RELATION_QUERY_CHUNK_SIZE, $this->maxQueryValues))) as $chunk) {

@fogelito fogelito Sep 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the const RELATION_QUERY_CHUNK_SIZE is useless , will never use it ..
We can always use $this->maxQueryValues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants