Add model_validator to CardDelegationConfig to enforce valid field combinations#149
Draft
Add model_validator to CardDelegationConfig to enforce valid field combinations#149
Conversation
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>
4 tasks
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CardDelegationConfigallowed constructing an empty or partially-populated instance (all fields optional), deferring validation failures to the backend. This adds a Pydanticmodel_validatorthat enforces valid combinations at construction time.Three valid modes (exactly one must be satisfied):
delegation_id— reuse an existing delegationcard_id— reuse an enrolled card; optionally overridespending_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
ValueErrorimmediately: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
Checklist:
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.