microsoft / microsoft/PowerPlatform-DataverseClient-Python

Feature Request: Support OData Deep Inserts in create() and upsert()

Đang mở
#149 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@sagebree đang làm issue này rồi.

Từ ngày 21/4/2026.

enhancement
Ngôn ngữ chính
Python
Star
60
Fork
23
Merge trung bình
13 giờ 53 phút
Pull request đã merge (30 ngày)
3

Mô tả

Summary

Add support for OData deep inserts in client.records.create() and client.records.upsert(), allowing parent and related child records to be created/upserted in a single API call.

Motivation

When importing data that involves a parent record and its related child records (e.g. via one-to-many relationships), the current SDK requires separate API calls for each table — first creating the parent, then creating each child record individually with a foreign key reference back to the parent. This is both verbose and inefficient, especially for bulk import scenarios.

The Dataverse Web API already natively supports deep inserts, where related records can be nested inside the parent payload using navigation property names. For example:

{
  "name": "Sample Account",
  "primarycontactid": {
    "firstname": "John",
    "lastname": "Smith"
  },
  "contact_customer_accounts": [
    { "firstname": "Jane", "lastname": "Doe" },
    { "firstname": "Bob", "lastname": "Jones" }
  ]
}

The SDK does not currently surface this capability. Attempting to pass nested dicts/lists in the record payload will not work correctly because _create() lowercases all keys via _lowercase_keys(), which breaks case-sensitive navigation property names.

Proposed Behavior

Allow create() and upsert() to accept nested dicts (for single-valued navigation properties) and lists of dicts (for collection-valued navigation properties) within the record payload. Navigation property keys should be preserved as-is (case-sensitive) and not lowercased.

Example usage:

# Deep insert: create parent + children in one call
client.records.create("account", {
    "name": "Contoso Ltd",
    "primarycontactid": {
        "firstname": "John",
        "lastname": "Smith"
    },
    "contact_customer_accounts": [
        {"firstname": "Jane", "lastname": "Doe"},
        {"firstname": "Bob", "lastname": "Jones"},
    ]
})

Current Workaround

Create parent and child records in separate calls, manually managing the foreign key references:

parent_id = client.records.create("account", {"name": "Contoso Ltd"})

client.records.create("contact", {
    "firstname": "Jane",
    "lastname": "Doe",
    "parentcustomerid_account@odata.bind": f"/accounts({parent_id})"
})

Additional Context

  • The Dataverse Web API documentation confirms deep insert support for both POST (create) and PATCH (upsert) operations.
  • The _lowercase_keys() call in _create() would need to distinguish between column names (which should be lowercased) and navigation property names (which are case-sensitive and should be preserved).
  • CreateMultiple / UpsertMultiple bulk operations may also benefit from this, depending on API support for deep inserts in batch payloads.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.