Skip to content

BaseModel.__init__ silently swallows unknown keyword arguments #17

Open

Description

@sveneberth

BaseModel.__init__ takes **kwargs and discards them without a word, while Error.__init__ and ErrorResponse.__init__ in the same package both logger.warning about leftovers. So every model silently accepts any keyword it does not know.

Measured:

>>> item = BasketItem(title="t", type="goods", quantitiy=3)
>>> item.kind, item.serialize()["type"], item.serialize()["quantity"]
(None, '', None)

type is the name the API itself uses and the name serialize() emits, so it is the first thing a reader reaches for — and quantitiy is an ordinary typo that drops a quantity out of a payment payload.

This is not hypothetical: the SDK's own sandbox tests passed type="goods" and were therefore sending an empty item type for as long as they existed. #13 corrected the two call sites in tests/, but examples/03_installment_plans.py:57 still has it — the one public example of building a basket item, i.e. what a downstream user copies:

amountPerUnitGross=AMOUNT, basketItemReferenceId="item-1", type="goods",

Two things worth doing:

  1. Fix the example.
  2. Mirror Error's behaviour in BaseModel.__init__ — a logger.warning on leftover kwargs. It needs BasketItem.fromDict and Basket.fromDict to pop the keys they deliberately pass through (type, id), which is a small change and makes the round trip explicit rather than accidental.

AGENTS.md announces a camelCase → snake_case rename for 2.0, which will turn every unported keyword into a silently empty field. A warning now is cheap insurance for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions