Skip to content

fix: clarify invalid reverse one-way relationship values - #975

Merged
HarshMN2345 merged 3 commits into
mainfrom
codex/fix-reverse-relationship-diagnostic
Sep 17, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
codex/fix-reverse-relationship-diagnostic

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 17, 2026

Copy link
Copy Markdown
Member

Creating a document with an array on the child side of a one-way one-to-one relationship failed with Must be either a document ID or a document, array given., although a document or an ID is rejected from that side too. The array branch of createDocumentRelationships() now reports the direction error first, as its document and ID branches and the update path already do.

testCreateInvalidOneWayChildArrayValueRelationship sits with the other testCreateInvalid*ValueRelationship tests and uses the object payload from the issue. It fails on main with the old message.

Related to appwrite/appwrite#8345. Appwrite gets the fix once it requires a release that contains this change.

Summary by CodeRabbit

  • Bug Fixes
    • One-to-one relationships configured as one-way now consistently reject values assigned from the child side.
    • Invalid child documents are not created, and the parent relationship remains unchanged.
    • Valid creation from the parent side continues to work as expected.

@coderabbitai

coderabbitai Bot commented Sep 17, 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: ae04ba35-e158-4cad-a88a-50b337d9778a

📥 Commits

Reviewing files that changed from the base of the PR and between 9f601bf and 1393df5.

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

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


📝 Walkthrough

Walkthrough

The database now rejects array values on the child side of one-way one-to-one relationships. End-to-end tests cover rejected child creation and successful parent-side creation.

Changes

One-way relationship validation

Layer / File(s) Summary
Relationship guard and end-to-end validation
src/Database/Database.php, tests/e2e/Adapter/Scopes/Relationships/OneToOneTests.php
The array branch now throws RelationshipException for invalid child-side values. The new test covers array, string, and nested document values, plus successful parent-side creation.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: abnegate

Merge Risk: ⚪ Minimal · up to 1393d

The changed validation and its tests cover the relevant array rejection path; no actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: clarifying validation for invalid reverse values in one-way relationships.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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-reverse-relationship-diagnostic

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.

@greptile-apps

greptile-apps Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The implementation appears safe to merge, with no new reportable correctness or security defects.

Summary

The PR makes one-way one-to-one relationships reject array values from the child side before array-cardinality validation.

  • Adds an early direction-specific validation error for child-side array values.
  • Relocates regression coverage into the shared relationship test suite.
  • Removes the earlier adapter-specific regression test.

Reviews (2) · Last reviewed commit: "test: cover the one-way child array valu..."

Comment thread tests/e2e/Adapter/Scopes/Relationships/OneToOneTests.php Outdated
Comment thread src/Database/Database.php
@@ -5998,6 +5998,10 @@ private function createDocumentRelationships(Document $collection, Document $doc
try {
switch (\gettype($value)) {
case 'array':

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.

Should this throw in case of array? Maybe should be Object (Document)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, it should. The child side is always invalid for one-way relationships, so arrays should hit the same error too. We only see an array here because that’s what reaches this code path.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To be precise, this only applies to one-way one-to-one. The Document case already throws the same error. The reason its an array here is that the child key isnt treated as an attribute, so it never gets converted to a Document. 🤔

@HarshMN2345
HarshMN2345 merged commit e45195f into main Sep 17, 2026
22 checks passed
@HarshMN2345
HarshMN2345 deleted the codex/fix-reverse-relationship-diagnostic branch September 17, 2026 08:18
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