diff --git a/CHANGELOG.md b/CHANGELOG.md index 28612e9..20299d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ 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 + +- **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 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..4b8dacd 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,24 @@ ) +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 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: + return None + return value + + +_LevelAgreementRef = Annotated[IdNameRef | None, BeforeValidator(_empty_list_as_none)] + + class _TicketTeamMember(GlpiModel): """One inline team-member entry of the ``Ticket.team`` array. @@ -158,7 +179,9 @@ class GetTicket(GlpiModel): 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. 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 @@ -217,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: IdNameRef | None = None - ola_tto: IdNameRef | None = None - sla_level_ttr: IdNameRef | None = None - ola_level_ttr: IdNameRef | None = 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 3f56c5e..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,6 +67,61 @@ def test_get_ticket_accepts_the_major_priority_level() -> None: assert ticket.priority.glpi_id == 6 +_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": None, + } + ) + assert ticket.sla_ttr is not None and ticket.sla_ttr.id == 5 + 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: """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