Skip to content

fix: include child table metadata in get_doctype_info#193

Merged
buildswithpaul merged 2 commits into
developfrom
fix/get-doctype-info-child-tables-192
Jun 8, 2026
Merged

fix: include child table metadata in get_doctype_info#193
buildswithpaul merged 2 commits into
developfrom
fix/get-doctype-info-child-tables-192

Conversation

@buildswithpaul

Copy link
Copy Markdown
Owner

Summary

get_doctype_info returned only top-level fields, so callers hitting create_document for a parent doctype (Sales Order, Purchase Order, etc.) had no way to discover the child DocType's own fields — and ended up creating the parent with empty child tables. create_document's own description (create_document.py:44) already tells the model "First use get_doctype_info to understand the DocType structure, identify required fields and child tables" — so the gap left the documented workflow broken.

This PR:

  1. Adds a child_tables list to the response — one entry per Table / Table MultiSelect field, including each child DocType's full field metadata (same shape as the parent fields array). Callers now have everything they need in a single tool call.
  2. Fixes is_single, which was reading meta.istable (child-table flag) instead of meta.issingle. Adds a separate is_child_table key so the two concepts stop being conflated.

Response shape (additions only)

{
  "is_single": false,
  "is_child_table": false,
  "child_tables": [
    {
      "fieldname": "items",
      "label": "Items",
      "fieldtype": "Table",
      "options": "Sales Order Item",
      "reqd": 1,
      "fields": [
        {"fieldname": "item_code", "fieldtype": "Link", "options": "Item", "reqd": 1, ...},
        {"fieldname": "qty", "fieldtype": "Float", "reqd": 1, ...},
        ...
      ]
    },
    ...
  ]
}

Type of Change

  • Bug fix
  • Feature

Related Issues

Fixes #192

Test Plan

  • Added test_get_doctype_metadata_includes_child_tables: asserts User.roles is present in child_tables with recursive field metadata (role field exposed inside).
  • Added test_get_doctype_metadata_distinguishes_single_from_child_table: System Settings returns is_single=True, is_child_table=False; Has Role returns is_single=False, is_child_table=True.
  • bench --site <site> run-tests --app frappe_assistant_core --module frappe_assistant_core.tests.test_metadata_tools — 21 tests pass (15 pre-existing placeholders skipped).
  • Manual sanity check via console against Sales Order: 6 child tables returned with full nested field metadata.

Checklist

  • I have targeted the develop branch (not main)
  • My code follows the existing code style
  • I have tested my changes locally
  • I have added/updated tests for the change

get_doctype_info previously returned only top-level fields, so callers
hitting create_document for a parent doctype (Sales Order, Purchase
Order, etc.) had no way to discover the child DocType's own fields and
ended up creating the parent with empty child tables. create_document's
own description already instructs the model to call get_doctype_info
first, so the gap left the workflow broken.

Add a child_tables list to the response — one entry per Table /
Table MultiSelect field — including each child DocType's full field
metadata (same shape as the parent fields array). Callers now have
everything they need in a single tool call.

Also fix is_single, which was reading meta.istable (child-table flag)
instead of meta.issingle, and add a separate is_child_table key so the
two concepts stop being conflated.

Tests: regression guard asserting `User` exposes its `roles` child
table with recursive field metadata, plus a single-vs-child-table
distinguishing test against `System Settings` and `Has Role`.
@buildswithpaul buildswithpaul merged commit ab5d794 into develop Jun 8, 2026
9 checks passed
@buildswithpaul buildswithpaul deleted the fix/get-doctype-info-child-tables-192 branch June 8, 2026 10:09
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.

[Feature]: get doc info Child table support

2 participants