Skip to content

gava-connect-plus v0.2.1

Choose a tag to compare

@IamMuuo IamMuuo released this 03 Jul 11:06
552c0d5

Release Notes - v0.2.1

Overview

Bug fix release addressing Pydantic validation errors and JSON serialization issues in the KRA invoice checker library.

Fixes

1. Nullable Field Validation Error

Issue: Pydantic validation was failing with Input should be a valid string error when the KRA API returned null values for optional fields.

Fix: Updated InvoiceDetails model to make the following fields Optional[str]:

  • customer_pin
  • customer_name
  • exemption_certificate_no
  • trader_system_invoice_number
  • relevant_invoice_date
  • relevant_invoice_number

These fields now correctly accept null values per KRA API documentation.

2. Decimal Serialization Error

Issue: JSON serialization was failing with Object of type Decimal is not JSON serializable when calling json.dumps() on invoice records containing monetary values.

Fix:

  • Configured monetary fields (total_invoice_amount, total_taxable_amount, total_tax_amount, total_discount_amount) to use Decimal type for precision.
  • Added model_config = ConfigDict(json_encoders={Decimal: str}) to InvoiceDetails model to serialize Decimal objects as strings, preventing floating-point precision loss.
  • Updated client-side serialization to use model_dump_json(indent=4) instead of json.dumps(record.model_dump()) to respect Pydantic's JSON encoder configuration.

Migration Guide

If you're serializing invoice responses, update your code:

Before:

json.dumps(record.model_dump(), indent=4)

After

record.model_dump_json(indent=4)

Tested With

  • Pydantic v2
  • httpx (with 20s timeout)
  • KRA API Sandbox