fix: validate mutually exclusive product_id/product in grant_product

The spec requires exactly one of product_id or product (inline definition).
Added validation to both sync and async grant_product methods to raise
ValueError if both or neither are provided, matching the existing
_resolve_customer_path pattern for customer identifiers.
This commit is contained in:
Ejiro Asiuwhu 2026-03-26 10:36:55 +01:00
parent f7786c3a80
commit b44fabc623

View File

@ -1299,8 +1299,11 @@ class StackServerApp:
None.
Raises:
ValueError: If not exactly one customer identifier is provided.
ValueError: If not exactly one customer identifier is provided,
or if both/neither of product_id and product are given.
"""
if (product_id is None) == (product is None):
raise ValueError("Provide exactly one of product_id or product, not both or neither")
ctype, cid, _ = _resolve_customer_path(user_id, team_id, custom_customer_id)
body = _build_params(
product_id=product_id,
@ -2650,8 +2653,11 @@ class AsyncStackServerApp:
None.
Raises:
ValueError: If not exactly one customer identifier is provided.
ValueError: If not exactly one customer identifier is provided,
or if both/neither of product_id and product are given.
"""
if (product_id is None) == (product is None):
raise ValueError("Provide exactly one of product_id or product, not both or neither")
ctype, cid, _ = _resolve_customer_path(user_id, team_id, custom_customer_id)
body = _build_params(
product_id=product_id,