Skip to content

Conversation

@ckeshava
Copy link
Collaborator

High Level Overview of Change

fix #885: Fix error in the Directory model of LedgerEntry request

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update CHANGELOG.md?

  • Yes
  • No, this change does not impact library users

Test Plan

Added new integration test to validate the correctness of the change.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Walkthrough

This change fixes a validation error in the Directory model for LedgerEntry requests by making the owner and dir_root fields optional and introducing a new sub_index field for pagination. The fix is validated by a new integration test that verifies Directory-based LedgerEntry operations using multiple input formats.

Changes

Cohort / File(s) Summary
Model Update
xrpl/models/requests/ledger_entry.py
Modified Directory class: made owner and dir_root fields optional (from required str to Optional[str] = None); added new sub_index: Optional[int] = None field for pagination; updated class docstring to reflect optional requirements and sub_index parameter.
Test Coverage
tests/integration/reqs/test_ledger_entry.py
Added new integration test file with TestLedgerEntry class; includes test_fetch_directory_model that validates Directory-based LedgerEntry operations across three modalities: Dataclass model input, JSON input, and ledger index lookup; tests wallet creation, DIDSet submission, and directory fetching.
Documentation
CHANGELOG.md
Added Fixed entry documenting the correction of the Directory model validation error in LedgerEntry request.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Areas requiring attention:
    • Verify that making owner and dir_root optional doesn't break validation logic elsewhere (confirm either field or a valid combination is required)
    • Check integration test setup and teardown procedures for proper cleanup
    • Validate that the sub_index field is properly documented and integrated with any paging logic in the LedgerEntry handler

Suggested reviewers

  • achowdhry-ripple
  • pdp2121

Poem

🐰 The Directory was stubborn, its fields locked tight,
But a rabbit came hopping to set things right,
Now owner alone can dance and play,
With sub_index friends to light the way! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix error in LedgerEntry request' is concise and accurately describes the main change: fixing an issue in the LedgerEntry request model, specifically the Directory class validation.
Description check ✅ Passed The description follows the template structure with High Level Overview, Type of Change clearly marked as a bug fix, and CHANGELOG.md confirmation. Test Plan mentions adding a new integration test. The PR links issue #885.
Linked Issues check ✅ Passed The PR addresses issue #885 by making dir_root optional in the Directory model, adding sub_index field, and includes integration tests validating the fix works across multiple fetch modalities.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #885: updating the Directory model fields in LedgerEntry, adding CHANGELOG documentation, and including integration tests to validate the fix.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
xrpl/models/requests/ledger_entry.py (1)

119-139: Missing validation for mutually-required fields.

The docstring states that the input "requires either dir_root or owner", but there's no _get_errors method to enforce this constraint. A Directory() with neither field set will pass model validation but fail at the XRPL server.

Consider adding validation similar to other models in this file:

🔎 Proposed validation method
 @require_kwargs_on_init
 @dataclass(frozen=True, **KW_ONLY_DATACLASS)
 class Directory(BaseModel):
     """
     The input requires either dir_root or owner as a sub-field, plus optionally a
     sub_index sub-field.
     """

     owner: Optional[str] = None
     """
     (Optional) Unique address of the account associated with this directory.
     """

     dir_root: Optional[str] = None
     """
     (Optional) Unique index identifying the directory to retrieve, as a hex string.
     """

     sub_index: Optional[int] = None
     """
     (Optional) If provided, jumps to a later "page" of the DirectoryNode.
     """
+
+    def _get_errors(self: Self) -> Dict[str, str]:
+        errors = super()._get_errors()
+        if self.owner is None and self.dir_root is None:
+            errors["Directory"] = "Must provide either `owner` or `dir_root`."
+        return errors

Note: You'll need to add Self to the imports from typing_extensions and Dict from typing if not already available in the class scope.

tests/integration/reqs/test_ledger_entry.py (2)

43-43: Use lowercase for local variables.

DIR_NODE_INDEX uses SCREAMING_SNAKE_CASE, which by Python convention is reserved for module-level constants. Since this is a local variable assigned at runtime, use snake_case.

🔎 Proposed fix
-        DIR_NODE_INDEX = response.result["index"]
+        dir_node_index = response.result["index"]

And update line 58:

-        response = await client.request(LedgerEntry(index=DIR_NODE_INDEX))
+        response = await client.request(LedgerEntry(index=dir_node_index))

36-60: Consider adding test coverage for dir_root retrieval.

The test validates fetching by owner, but per the updated model, dir_root is an equally valid alternative. Consider adding a test case that fetches the directory using dir_root to ensure both code paths work correctly.

🔎 Example addition after line 42
        # fetch the directory using dir_root
        response = await client.request(
            LedgerEntry(directory=Directory(dir_root=dir_node_index))
        )
        self.assertTrue(response.is_successful())
        self.assertEqual(response.result["node"]["LedgerEntryType"], "DirectoryNode")
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1464e9e and 1eb87ac.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • tests/integration/reqs/test_ledger_entry.py (1 hunks)
  • xrpl/models/requests/ledger_entry.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Integration test (3.10)
  • GitHub Check: Integration test (3.11)
  • GitHub Check: Integration test (3.12)
  • GitHub Check: Integration test (3.13)
  • GitHub Check: Integration test (3.8)
  • GitHub Check: Integration test (3.14)
  • GitHub Check: Integration test (3.9)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
CHANGELOG.md (1)

10-12: LGTM!

The changelog entry is clear, properly placed under the Unreleased/Fixed section, and follows the existing format.

tests/integration/reqs/test_ledger_entry.py (1)

16-60: Good test coverage for the fix.

The test properly validates the fix by:

  1. Creating a directory entry via DIDSet
  2. Fetching using the Directory dataclass with optional fields
  3. Fetching using a JSON dict
  4. Fetching by ledger index

This confirms the model now accepts owner without requiring dir_root.

"""
Required fields for requesting a DirectoryNode if not querying by
object ID.
The input requires either dir_root or owner as a sub-field, plus optionally a
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably be checked in the model validation

Comment on lines +121 to +122
The input requires either dir_root or owner as a sub-field, plus optionally a
sub_index sub-field.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
The input requires either dir_root or owner as a sub-field, plus optionally a
sub_index sub-field.
Required fields for requesting a DirectoryNode if not querying by
object ID.
The input requires either dir_root or owner as a sub-field, plus optionally a
sub_index sub-field.

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.

Request model error xrpl.models.requests.ledger_entry.Directory

3 participants