Skip to content

fix(2.2.1): make optional Session/ChargingPeriod fields omittable#27

Open
nghildebrandt wants to merge 2 commits into
mainfrom
fix/optional-session-fields
Open

fix(2.2.1): make optional Session/ChargingPeriod fields omittable#27
nghildebrandt wants to merge 2 commits into
mainfrom
fix/optional-session-fields

Conversation

@nghildebrandt

Copy link
Copy Markdown
Contributor

Several OCPI 2.2.1 fields were declared X | None without a default, which in Pydantic v2 makes them required-but-nullable — a counterparty that omits the field entirely (rather than sending null) gets a 422.

Observed live: SMATRICS pushes Sessions whose charging_periods[] omit tariff_id → every PUT/PATCH to our sessions receiver returned 422 Unprocessable Entity.

Fix

Add = None defaults so these can be omitted:

  • ChargingPeriod.tariff_id
  • Session.end_date_time, Session.authorization_reference, Session.meter_id, Session.total_cost

All are optional per the OCPI 2.2.1 spec. Verified: a PATCH with charging_periods missing tariff_id, and a full PUT omitting these optionals, both validate now (deployed to dev — pushes that were 422 now return 200 and persist).

🤖 Generated with Claude Code

Several "X | None" fields had no default, so they were required-but-nullable —
a counterparty (SMATRICS) that omits them entirely got a 422. Add `= None`
defaults to ChargingPeriod.tariff_id and Session.end_date_time /
authorization_reference / meter_id / total_cost so omitting them is accepted.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The 2.2.1 sessions receiver called adapter.session_adapter() without a version,
so it defaulted to VersionNumber.latest (2.3.0) and re-validated the stored
session against the newer/stricter 2.3.0 schema. A session valid under 2.2.1
(e.g. omitting tariff_id / end_date_time, optional there) then raised a
ValidationError on PATCH/GET → surfaced as OCPI status_code 3000. Pin all
session_adapter() calls in the 2.2.1 cpo/emsp receivers to VersionNumber.v_2_2_1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant