fix(2.2.1): make optional Session/ChargingPeriod fields omittable#27
Open
nghildebrandt wants to merge 2 commits into
Open
fix(2.2.1): make optional Session/ChargingPeriod fields omittable#27nghildebrandt wants to merge 2 commits into
nghildebrandt wants to merge 2 commits into
Conversation
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>
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.
Several OCPI 2.2.1 fields were declared
X | Nonewithout a default, which in Pydantic v2 makes them required-but-nullable — a counterparty that omits the field entirely (rather than sendingnull) gets a 422.Observed live: SMATRICS pushes Sessions whose
charging_periods[]omittariff_id→ every PUT/PATCH to our sessions receiver returned422 Unprocessable Entity.Fix
Add
= Nonedefaults so these can be omitted:ChargingPeriod.tariff_idSession.end_date_time,Session.authorization_reference,Session.meter_id,Session.total_costAll are optional per the OCPI 2.2.1 spec. Verified: a PATCH with
charging_periodsmissingtariff_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