Skip to content

Mongo array dates #908

Open
fogelito wants to merge 2 commits into
mainfrom
mongo-array-datetime
Open

Mongo array dates #908
fogelito wants to merge 2 commits into
mainfrom
mongo-array-datetime

Conversation

@fogelito

@fogelito fogelito commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of nested document data so non-array values no longer trigger errors during processing.
    • Fixed support for datetime arrays, ensuring values can be saved and read back consistently in the original order.
  • Tests
    • Added end-to-end coverage for datetime array documents to verify round-trip behavior.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@fogelito, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a0a908f5-0758-44b2-ba9b-a2094c657f8d

📥 Commits

Reviewing files that changed from the base of the PR and between 7864b63 and c597ffa.

📒 Files selected for processing (1)
  • src/Database/Document.php
📝 Walkthrough

Walkthrough

Document::__construct now guards sub-document wrapping with is_array($child) before accessing $child['$id']/$child['$collection'], preventing errors on non-array children. A new e2e test testDateTimeArrayDocument() verifies datetime array attributes round-trip correctly.

Changes

Datetime Array Sub-document Fix

Layer / File(s) Summary
Array guard + e2e test
src/Database/Document.php, tests/e2e/Adapter/Scopes/DocumentTests.php
__construct now checks is_array($child) before sub-document wrapping; testDateTimeArrayDocument() creates a collection with a datetime array attribute, inserts two values, and asserts correct retrieval via createDocument and find.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Suggested reviewers

  • abnegate

Poem

🐇 A guard was added, oh what a treat,
No more crashes when dates we meet.
is_array checked before the wrap,
DateTime arrays fill the gap.
Hop along, the tests all pass! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main change: handling Mongo datetime arrays.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mongo-array-datetime

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.

@fogelito fogelito mentioned this pull request Jun 29, 2026
@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a fatal error in the Document constructor when a MongoDB adapter returns non-array scalar/object values (e.g. UTCDateTime) inside an array attribute: the old code tried array-access on every element before checking whether it actually was an array.

  • Document.php: Adds a leading \is_array($child) guard before the isset($child['$id']) checks so non-array elements (dates, numbers, strings, BSON objects) are skipped without error; removing the now-redundant !$child instanceof self is safe because is_array() already returns false for Document/ArrayObject instances.
  • DocumentTests.php: New testDateTimeArrayDocument test verifies the round-trip (create → getDocumentfind) for a two-element datetime array, pinning the regression fix.

Confidence Score: 5/5

The change is a minimal, well-targeted guard that prevents a fatal error without altering any existing behavior for valid nested-document arrays.

Both changed lines are in the Document constructor's array-iteration loop. The new is_array() check is strictly narrower than the old one: it skips non-array values (the bug), and the removed !$child instanceof self clause is already covered because Document extends ArrayObject is never a native PHP array. The accompanying e2e test exercises create, read, and find paths. No edge cases are missed.

No files require special attention.

Important Files Changed

Filename Overview
src/Database/Document.php Adds is_array() guard before iterating array children, preventing fatal error when Mongo returns non-array objects (e.g. UTCDateTime) inside an array field; also implicitly covers the removed !$child instanceof self check since Document extends ArrayObject and is not a native array.
tests/e2e/Adapter/Scopes/DocumentTests.php Adds testDateTimeArrayDocument end-to-end test covering creation, getDocument, and find round-trips for a datetime array field.

Reviews (2): Last reviewed commit: "Message" | Re-trigger Greptile

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.

1 participant