Skip to content

Add pending reason operations: catalogue read and per-ticket get, set and clear - #53

Merged
baraline merged 4 commits into
mainfrom
feat/pending-reasons
Nov 23, 2026
Merged

baraline merged 4 commits into
mainfrom
feat/pending-reasons

Conversation

@baraline

@baraline baraline commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Problem

A GLPI ticket set to Pending (status 4) can carry a pending reason from the instance's catalogue, and the client had no way to read or set it. The v2 API lists the catalogue (/Assistance/PendingReason). But its ticket-item schema omits the catalogue id, and no v2 route writes an item. So the per-ticket part has to go through the legacy v1 API (PendingReason_Item).

Fix

A new PendingReasonMixin on both clients:

  • list_pending_reasons and iter_pending_reasons read the catalogue through v2.
  • get_ticket_pending_reason, set_ticket_pending_reason and clear_ticket_pending_reason handle a ticket's item through v1, so they need the v1 session and raise RuntimeError without one.
    • set_ticket_pending_reason reads the item first, creates it (POST) or updates it (PUT), and returns it read back.
    • It does not change the ticket status: the caller sets status 4 itself.
    • clear_ticket_pending_reason returns whether an item was deleted.
  • New read models PendingReason and PendingReasonItem, exported from the package root and from glpi_python_client.models.
  • Docs in the API reference and the user guide, and notes in the setup and ticket-workflow skills. The docs state these limits:
    • set is a read then a write, so two concurrent sets can race;
    • an item set on a ticket that never goes to Pending has no effect;
    • GLPI deletes the item when the ticket leaves Pending.

Tests

Unit tests on both trees cover:

  • the catalogue read, and paging that stops on a short page;
  • get, with and without an item;
  • set on the create (POST) and update (PUT) paths, its zero defaults, and a result it cannot read back;
  • clear, with an item and without one (no DELETE sent);
  • the missing v1 session error;
  • the model exports.

The methods were also checked by hand against a live GLPI instance (v2 and legacy v1 APIs), on a throwaway ticket, 16 checks passed:

  • the catalogue lists its reason, and the iterator pages it;
  • set creates the item, and a second set updates the same item;
  • get reads it, and set changes neither the status nor the followups;
  • clear removes it, and a second clear returns False;
  • moving the ticket out of Pending removes the item.

Locally, ruff check, mypy glpi_python_client, unasync_build.py --check and the sphinx -W build pass, and so do the test files this branch touches (32 passed). The full suite and the coverage gate run in CI.

Overlaps with other open PRs

This PR only conflicts with the other open PRs (#50, #51, #52) in CHANGELOG.md: keep both entries.

Suggested merge order: #50, #51, #52, #53. After each merge I rebase the next branch: the conflicts are the CHANGELOG.md entries, plus one import line in _v1_session.py for #51.

🤖 Generated with Claude Code

baraline and others added 3 commits November 23, 2026 00:44
…read and the v1 per-ticket item get, set and clear, with their models and docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… on its own line instead of continuing the previous bullet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…item on a never-pending ticket, and the v1 session requirement in the setup guidance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 98.71795% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.14%. Comparing base (f6feada) to head (98523d9).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...t/_async/clients/api/assistance/_pending_reason.py 98.03% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   98.13%   98.14%   +0.01%     
==========================================
  Files          97       99       +2     
  Lines        3908     3985      +77     
==========================================
+ Hits         3835     3911      +76     
- Misses         73       74       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@baraline
baraline merged commit 84f7bab into main Nov 23, 2026
6 checks passed
@baraline
baraline deleted the feat/pending-reasons branch November 23, 2026 08:49
@baraline baraline mentioned this pull request Nov 23, 2026
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.

2 participants