From 3fef83deec778742b0b3762f7511709bde69864e Mon Sep 17 00:00:00 2001 From: baraline Date: Tue, 10 Nov 2026 10:24:46 +0100 Subject: [PATCH 1/2] Read GLPI 12's empty ola_ttr / ola_tto arrays as no OLA, so ticket reads work against a GLPI 12 server GLPI 12.0.1 sends `ola_ttr` and `ola_tto` as `[]` on every ticket without an OLA. Its own v2.3 contract, like GLPI 11, declares a nullable `{"id", "name"}` object there. `GetTicket` typed both fields `IdNameRef | None` and refused the array. Every `get_ticket`, and every search that returns a ticket without an OLA, therefore raised `ValidationError` against GLPI 12. `ola_ttr`, `ola_tto` and `ola_level_ttr` now go through a before-validator that turns an empty list into `None` and passes every other value on unchanged. An OLA object and `null` read as before. The SLA fields are untouched: GLPI 12 still sends them as an object or `null`. Measured against a GLPI 12.0.1 server: - Every ticket read came back with `ola_ttr: []` and `ola_tto: []`, including tickets that carry an SLA. - An RSQL filter on `ola_ttr.id` answers HTTP 500, so a populated OLA's shape on GLPI 12 could not be observed, and this change makes no assumption about it. - A saved GLPI 12 ticket payload now validates unchanged. The new test fails on the old model and passes with the fix. The version moves to 0.6.9. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 13 +++++++ glpi_python_client/__init__.py | 2 +- .../models/api_schema/assistance/_ticket.py | 34 ++++++++++++++--- .../tests/test_assistance_schemas.py | 37 +++++++++++++++++++ pyproject.toml | 2 +- skills/glpi-asset-workflow/SKILL.md | 2 +- skills/glpi-client-setup/SKILL.md | 2 +- skills/glpi-contract-workflow/SKILL.md | 2 +- skills/glpi-document-workflow/SKILL.md | 2 +- skills/glpi-knowledge-base/SKILL.md | 2 +- skills/glpi-plugin-fields/SKILL.md | 2 +- skills/glpi-reporting-and-context/SKILL.md | 2 +- skills/glpi-team-members/SKILL.md | 2 +- skills/glpi-ticket-timeline/SKILL.md | 2 +- skills/glpi-ticket-workflow/SKILL.md | 2 +- .../glpi-user-location-provisioning/SKILL.md | 2 +- 16 files changed, 91 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28612e9..0d50707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## 0.6.9 — 2026-11-10 + +A fix for GLPI 12. GLPI 12.0.1 sends a ticket's `ola_ttr` and `ola_tto` as an +empty array, `[]`, when the ticket has no OLA. Its own v2.3 contract, like +GLPI 11, declares a nullable object there. `GetTicket` refused the array, so +every ticket read and every ticket search raised `ValidationError` against a +GLPI 12 server. + +### Fixed + +- **`GetTicket.ola_ttr`, `ola_tto` and `ola_level_ttr`** read an empty array as + `None`. An object and `null` read as before. Nothing else changes. + ## 0.6.8 — 2026-11-02 A minor addition: a way to write or clear a ticket's take-into-account stamp, diff --git a/glpi_python_client/__init__.py b/glpi_python_client/__init__.py index 849e8f1..d3a884c 100644 --- a/glpi_python_client/__init__.py +++ b/glpi_python_client/__init__.py @@ -138,7 +138,7 @@ date_window, ) -__version__ = "0.6.8" +__version__ = "0.6.9" __all__ = [ "AsyncGlpiClient", diff --git a/glpi_python_client/models/api_schema/assistance/_ticket.py b/glpi_python_client/models/api_schema/assistance/_ticket.py index 40c85fe..1185c25 100644 --- a/glpi_python_client/models/api_schema/assistance/_ticket.py +++ b/glpi_python_client/models/api_schema/assistance/_ticket.py @@ -22,6 +22,9 @@ from datetime import datetime from functools import cached_property +from typing import Annotated + +from pydantic import BeforeValidator from glpi_python_client.models._base import GlpiModel from glpi_python_client.models.api_schema._common import ( @@ -41,6 +44,22 @@ ) +def _empty_list_as_none(value: object) -> object: + """Read an empty JSON array as an absent reference. + + GLPI 12 sends ``ola_ttr`` and ``ola_tto`` as ``[]`` on a ticket with no + OLA, where its own v2.3 contract, like GLPI 11, declares a nullable + ``{"id", "name"}`` object. Every other value is passed on unchanged. + """ + + if isinstance(value, list) and not value: + return None + return value + + +_OlaRef = Annotated[IdNameRef | None, BeforeValidator(_empty_list_as_none)] + + class _TicketTeamMember(GlpiModel): """One inline team-member entry of the ``Ticket.team`` array. @@ -152,13 +171,16 @@ class GetTicket(GlpiModel): sla_tto : IdNameRef | None, optional SLA applied for time-to-own. ola_ttr : IdNameRef | None, optional - OLA applied for time-to-resolve. + OLA applied for time-to-resolve. The empty array GLPI 12 sends for + a ticket with no OLA reads as :data:`None`. ola_tto : IdNameRef | None, optional - OLA applied for time-to-own. + OLA applied for time-to-own. The empty array GLPI 12 sends for a + ticket with no OLA reads as :data:`None`. sla_level_ttr : IdNameRef | None, optional SLA level escalation step for time-to-resolve. ola_level_ttr : IdNameRef | None, optional - OLA level escalation step for time-to-resolve. + OLA level escalation step for time-to-resolve. An empty array reads + as :data:`None`, as for ``ola_ttr``. sla_waiting_duration : int | None, optional Total SLA waiting duration in seconds (contract field ``sla_waiting_duration`` — ``Total SLA waiting duration in @@ -219,10 +241,10 @@ class GetTicket(GlpiModel): take_into_account_duration: int | None = None sla_ttr: IdNameRef | None = None sla_tto: IdNameRef | None = None - ola_ttr: IdNameRef | None = None - ola_tto: IdNameRef | None = None + ola_ttr: _OlaRef = None + ola_tto: _OlaRef = None sla_level_ttr: IdNameRef | None = None - ola_level_ttr: IdNameRef | None = None + ola_level_ttr: _OlaRef = None sla_waiting_duration: int | None = None ola_waiting_duration: int | None = None ola_ttr_begin_date: datetime | None = None diff --git a/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py b/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py index 3f56c5e..f5920d4 100644 --- a/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py +++ b/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py @@ -67,6 +67,43 @@ def test_get_ticket_accepts_the_major_priority_level() -> None: assert ticket.priority.glpi_id == 6 +def test_get_ticket_reads_glpi_12_empty_ola_arrays_as_none() -> None: + """GLPI 12's ``[]`` for a ticket with no OLA reads as no OLA. + + GLPI 12.0.1 sends ``ola_ttr`` and ``ola_tto`` as an empty array on every + ticket without an OLA, where its v2.3 contract and GLPI 11 give a + nullable object. ``GetTicket`` used to raise ``ValidationError`` on it, + which failed every ticket read and every search against such a server. + """ + + ticket = GetTicket.model_validate( + { + "id": 1, + "ola_ttr": [], + "ola_tto": [], + "ola_level_ttr": [], + "sla_ttr": {"id": 5, "name": "TTR 4h"}, + "sla_tto": None, + } + ) + assert ticket.ola_ttr is None + assert ticket.ola_tto is None + assert ticket.ola_level_ttr is None + assert ticket.sla_ttr is not None and ticket.sla_ttr.id == 5 + assert ticket.sla_tto is None + + +def test_get_ticket_still_reads_an_ola_object_and_null() -> None: + """The contract's own shapes, an object and ``null``, are unchanged.""" + + ticket = GetTicket.model_validate( + {"id": 1, "ola_ttr": {"id": 3, "name": "OLA 8h"}, "ola_tto": None} + ) + assert ticket.ola_ttr is not None + assert (ticket.ola_ttr.id, ticket.ola_ttr.name) == (3, "OLA 8h") + assert ticket.ola_tto is None + + def test_urgency_and_impact_still_span_one_to_five() -> None: """The five contract-declared levels keep their identifiers. diff --git a/pyproject.toml b/pyproject.toml index cc39cc9..bd797b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ exclude = [ [project] name = "glpi-python-client" -version = "0.6.8" +version = "0.6.9" description = "A typed Python client for GLPI ITSM APIs." readme = "README.md" requires-python = ">=3.11" diff --git a/skills/glpi-asset-workflow/SKILL.md b/skills/glpi-asset-workflow/SKILL.md index f779b00..6fb7287 100644 --- a/skills/glpi-asset-workflow/SKILL.md +++ b/skills/glpi-asset-workflow/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and credentials allowed to read or write assets." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Asset Workflow diff --git a/skills/glpi-client-setup/SKILL.md b/skills/glpi-client-setup/SKILL.md index d3fb4cc..bfd4efe 100644 --- a/skills/glpi-client-setup/SKILL.md +++ b/skills/glpi-client-setup/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to a GLPI v2 API, and valid GLPI credentials." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Client Setup diff --git a/skills/glpi-contract-workflow/SKILL.md b/skills/glpi-contract-workflow/SKILL.md index 235dcd3..08d851a 100644 --- a/skills/glpi-contract-workflow/SKILL.md +++ b/skills/glpi-contract-workflow/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and credentials allowed to read or write contracts." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Contract Workflow diff --git a/skills/glpi-document-workflow/SKILL.md b/skills/glpi-document-workflow/SKILL.md index 47584f4..cf4111d 100644 --- a/skills/glpi-document-workflow/SKILL.md +++ b/skills/glpi-document-workflow/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and v1 credentials configured on the client for binary uploads." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Document Workflow diff --git a/skills/glpi-knowledge-base/SKILL.md b/skills/glpi-knowledge-base/SKILL.md index ebbb0fd..6291611 100644 --- a/skills/glpi-knowledge-base/SKILL.md +++ b/skills/glpi-knowledge-base/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and — for category writes only — a legacy v1 session (v1_base_url + v1_user_token)." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Knowledge Base diff --git a/skills/glpi-plugin-fields/SKILL.md b/skills/glpi-plugin-fields/SKILL.md index 28a18d5..a8c3805 100644 --- a/skills/glpi-plugin-fields/SKILL.md +++ b/skills/glpi-plugin-fields/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, the GLPI Fields plugin installed server-side, and a legacy v1 session (v1_base_url + v1_user_token) — every method in this family goes over the v1 API." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Plugin Fields diff --git a/skills/glpi-reporting-and-context/SKILL.md b/skills/glpi-reporting-and-context/SKILL.md index b3bab7c..dc10de1 100644 --- a/skills/glpi-reporting-and-context/SKILL.md +++ b/skills/glpi-reporting-and-context/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and credentials allowed to read tickets, tasks, users, entities, and timeline records." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Reporting And Context diff --git a/skills/glpi-team-members/SKILL.md b/skills/glpi-team-members/SKILL.md index ce09af6..1e87501 100644 --- a/skills/glpi-team-members/SKILL.md +++ b/skills/glpi-team-members/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and credentials allowed to manage ticket teams." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Team Members diff --git a/skills/glpi-ticket-timeline/SKILL.md b/skills/glpi-ticket-timeline/SKILL.md index a761746..3c3467c 100644 --- a/skills/glpi-ticket-timeline/SKILL.md +++ b/skills/glpi-ticket-timeline/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, and network access to the GLPI v2 API." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Ticket Timeline diff --git a/skills/glpi-ticket-workflow/SKILL.md b/skills/glpi-ticket-workflow/SKILL.md index 29d240e..929cee3 100644 --- a/skills/glpi-ticket-workflow/SKILL.md +++ b/skills/glpi-ticket-workflow/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and credentials accepted by GlpiClient." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI Ticket Workflow diff --git a/skills/glpi-user-location-provisioning/SKILL.md b/skills/glpi-user-location-provisioning/SKILL.md index de7fca5..48be143 100644 --- a/skills/glpi-user-location-provisioning/SKILL.md +++ b/skills/glpi-user-location-provisioning/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: "Requires Python 3.11+, glpi-python-client, network access to the GLPI v2 API, and credentials allowed to read or write users, locations, and entities." metadata: package: glpi-python-client - version: "0.6.8" + version: "0.6.9" --- # GLPI User, Location, And Entity Provisioning From 8e9bd4e4b8334eb7c3a9e5b730007cef1a62614c Mon Sep 17 00:00:00 2001 From: baraline Date: Tue, 10 Nov 2026 10:40:04 +0100 Subject: [PATCH 2/2] Apply the empty-array read to all six SLA and OLA references of GetTicket, not only the OLA ones On GLPI 12.0.1 only `ola_ttr` and `ola_tto` were seen as `[]`. The SLA references (`sla_ttr`, `sla_tto`, `sla_level_ttr`) use the same reference shape, so they now read through the same before-validator, and the same quirk on any of them cannot fail a ticket read. The alias `_OlaRef` is renamed `_LevelAgreementRef`. The tests are parametrised over all six fields: - `[]` reads as `None`. - An object reads as before. - `null` reads as before. - A GLPI 12 ticket shape with an SLA and no OLA reads correctly. Reverting `sla_ttr` alone to plain `IdNameRef | None` fails exactly its own `[]` case. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +- .../models/api_schema/assistance/_ticket.py | 29 +++++----- .../tests/test_assistance_schemas.py | 58 ++++++++++++------- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d50707..20299d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ GLPI 12 server. ### Fixed -- **`GetTicket.ola_ttr`, `ola_tto` and `ola_level_ttr`** read an empty array as +- **All six SLA and OLA references of `GetTicket`** (`sla_ttr`, `sla_tto`, + `sla_level_ttr`, `ola_ttr`, `ola_tto`, `ola_level_ttr`) read an empty array as `None`. An object and `null` read as before. Nothing else changes. ## 0.6.8 — 2026-11-02 diff --git a/glpi_python_client/models/api_schema/assistance/_ticket.py b/glpi_python_client/models/api_schema/assistance/_ticket.py index 1185c25..4b8dacd 100644 --- a/glpi_python_client/models/api_schema/assistance/_ticket.py +++ b/glpi_python_client/models/api_schema/assistance/_ticket.py @@ -49,7 +49,9 @@ def _empty_list_as_none(value: object) -> object: GLPI 12 sends ``ola_ttr`` and ``ola_tto`` as ``[]`` on a ticket with no OLA, where its own v2.3 contract, like GLPI 11, declares a nullable - ``{"id", "name"}`` object. Every other value is passed on unchanged. + ``{"id", "name"}`` object. Every SLA and OLA reference of + :class:`GetTicket` reads through this, so the same quirk on any of them + cannot fail a ticket read. Every other value is passed on unchanged. """ if isinstance(value, list) and not value: @@ -57,7 +59,7 @@ def _empty_list_as_none(value: object) -> object: return value -_OlaRef = Annotated[IdNameRef | None, BeforeValidator(_empty_list_as_none)] +_LevelAgreementRef = Annotated[IdNameRef | None, BeforeValidator(_empty_list_as_none)] class _TicketTeamMember(GlpiModel): @@ -171,16 +173,15 @@ class GetTicket(GlpiModel): sla_tto : IdNameRef | None, optional SLA applied for time-to-own. ola_ttr : IdNameRef | None, optional - OLA applied for time-to-resolve. The empty array GLPI 12 sends for - a ticket with no OLA reads as :data:`None`. + OLA applied for time-to-resolve. ola_tto : IdNameRef | None, optional - OLA applied for time-to-own. The empty array GLPI 12 sends for a - ticket with no OLA reads as :data:`None`. + OLA applied for time-to-own. sla_level_ttr : IdNameRef | None, optional SLA level escalation step for time-to-resolve. ola_level_ttr : IdNameRef | None, optional - OLA level escalation step for time-to-resolve. An empty array reads - as :data:`None`, as for ``ola_ttr``. + OLA level escalation step for time-to-resolve. On all six SLA and + OLA references an empty array reads as :data:`None`: GLPI 12 sends + ``[]`` for ``ola_ttr`` and ``ola_tto`` on a ticket with no OLA. sla_waiting_duration : int | None, optional Total SLA waiting duration in seconds (contract field ``sla_waiting_duration`` — ``Total SLA waiting duration in @@ -239,12 +240,12 @@ class GetTicket(GlpiModel): request_type: IdNameRef | None = None take_into_account_date: datetime | None = None take_into_account_duration: int | None = None - sla_ttr: IdNameRef | None = None - sla_tto: IdNameRef | None = None - ola_ttr: _OlaRef = None - ola_tto: _OlaRef = None - sla_level_ttr: IdNameRef | None = None - ola_level_ttr: _OlaRef = None + sla_ttr: _LevelAgreementRef = None + sla_tto: _LevelAgreementRef = None + ola_ttr: _LevelAgreementRef = None + ola_tto: _LevelAgreementRef = None + sla_level_ttr: _LevelAgreementRef = None + ola_level_ttr: _LevelAgreementRef = None sla_waiting_duration: int | None = None ola_waiting_duration: int | None = None ola_ttr_begin_date: datetime | None = None diff --git a/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py b/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py index f5920d4..f362628 100644 --- a/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py +++ b/glpi_python_client/models/api_schema/assistance/tests/test_assistance_schemas.py @@ -67,41 +67,59 @@ def test_get_ticket_accepts_the_major_priority_level() -> None: assert ticket.priority.glpi_id == 6 -def test_get_ticket_reads_glpi_12_empty_ola_arrays_as_none() -> None: - """GLPI 12's ``[]`` for a ticket with no OLA reads as no OLA. +_LEVEL_AGREEMENT_FIELDS = ( + "sla_ttr", + "sla_tto", + "ola_ttr", + "ola_tto", + "sla_level_ttr", + "ola_level_ttr", +) + + +@pytest.mark.parametrize("field", _LEVEL_AGREEMENT_FIELDS) +def test_get_ticket_reads_an_empty_sla_or_ola_array_as_none(field: str) -> None: + """GLPI 12's ``[]`` for a missing SLA or OLA reads as none. GLPI 12.0.1 sends ``ola_ttr`` and ``ola_tto`` as an empty array on every ticket without an OLA, where its v2.3 contract and GLPI 11 give a nullable object. ``GetTicket`` used to raise ``ValidationError`` on it, which failed every ticket read and every search against such a server. + All six SLA and OLA references read the same way. """ + ticket = GetTicket.model_validate({"id": 1, field: []}) + assert getattr(ticket, field) is None + + +@pytest.mark.parametrize("field", _LEVEL_AGREEMENT_FIELDS) +def test_get_ticket_still_reads_an_sla_or_ola_object_and_null(field: str) -> None: + """The contract's own shapes, an object and ``null``, are unchanged.""" + + ticket = GetTicket.model_validate({"id": 1, field: {"id": 3, "name": "8h"}}) + ref = getattr(ticket, field) + assert ref is not None + assert (ref.id, ref.name) == (3, "8h") + assert getattr(GetTicket.model_validate({"id": 1, field: None}), field) is None + + +def test_get_ticket_reads_a_glpi_12_ticket_with_an_sla_and_no_ola() -> None: + """The shape GLPI 12 sends for a ticket with an SLA and no OLA.""" + ticket = GetTicket.model_validate( { "id": 1, + "sla_ttr": {"id": 5, "name": "TTR 4h"}, + "sla_tto": {"id": 6, "name": "TTO 1h"}, + "sla_level_ttr": None, "ola_ttr": [], "ola_tto": [], - "ola_level_ttr": [], - "sla_ttr": {"id": 5, "name": "TTR 4h"}, - "sla_tto": None, + "ola_level_ttr": None, } ) - assert ticket.ola_ttr is None - assert ticket.ola_tto is None - assert ticket.ola_level_ttr is None assert ticket.sla_ttr is not None and ticket.sla_ttr.id == 5 - assert ticket.sla_tto is None - - -def test_get_ticket_still_reads_an_ola_object_and_null() -> None: - """The contract's own shapes, an object and ``null``, are unchanged.""" - - ticket = GetTicket.model_validate( - {"id": 1, "ola_ttr": {"id": 3, "name": "OLA 8h"}, "ola_tto": None} - ) - assert ticket.ola_ttr is not None - assert (ticket.ola_ttr.id, ticket.ola_ttr.name) == (3, "OLA 8h") - assert ticket.ola_tto is None + assert ticket.sla_tto is not None and ticket.sla_tto.id == 6 + assert ticket.ola_ttr is None and ticket.ola_tto is None def test_urgency_and_impact_still_span_one_to_five() -> None: