Skip to content

Add model_validator to CardDelegationConfig to enforce valid field combinations#149

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/sub-pr-147-again
Draft

Add model_validator to CardDelegationConfig to enforce valid field combinations#149
Copilot wants to merge 3 commits intomainfrom
copilot/sub-pr-147-again

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

Description

CardDelegationConfig allowed constructing an empty or partially-populated instance (all fields optional), deferring validation failures to the backend. This adds a Pydantic model_validator that enforces valid combinations at construction time.

Three valid modes (exactly one must be satisfied):

  • delegation_id — reuse an existing delegation
  • card_id — reuse an enrolled card; optionally override spending_limit_cents, duration_secs, currency, etc.
  • provider_payment_method_id + spending_limit_cents + duration_secs — create a brand-new delegation (all three required)

An empty config or a partial new-delegation config now raises ValueError immediately:

# Raises: "CardDelegationConfig requires at least one of: ..."
CardDelegationConfig()

# Raises: missing field listed in error
CardDelegationConfig(provider_payment_method_id="pm_123", spending_limit_cents=5000)

# Valid — reuse card with optional overrides
CardDelegationConfig(card_id="pm-card-abc", spending_limit_cents=5000, duration_secs=3600)

Docstring updated to clearly document all three modes and their field requirements. 10 new unit tests cover valid and invalid combinations.

Is this PR related with an open issue?

Related to PR #147 — addresses review feedback

Types of changes

  • 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 change)

Checklist:

  • Follows the code style of this project.
  • Tests Cover Changes
  • Documentation

Funny gif


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

aaitor and others added 2 commits March 3, 2026 11:15
Add `card_id` and `delegation_id` fields to CardDelegationConfig for
reusing existing delegations and targeting specific cards. Add
`DelegationSummary` model and `list_delegations()` method to
DelegationAPI.

Refs: nevermined-io/internal#882

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…binations

Co-authored-by: aaitor <1726644+aaitor@users.noreply.github.com>
Copilot AI changed the title [WIP] Update card delegation guard-rails for Python SDK Add model_validator to CardDelegationConfig to enforce valid field combinations Mar 3, 2026
Base automatically changed from feat/payment-guardrails to main March 9, 2026 13:46
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