Skip to content

Consider create_*_and_fetch helpers; keep the int-returning primitives #35

Description

@baraline

Current state

Every write surfaces an id or nothing: 12 create_* methods return int,
link_ticket_timeline_document returns int, upload_document returns dict[str, object], and all 13
update_* plus 11 delete_* return None.

Correcting a common justification

-> int reflects what the client keeps, not what GLPI sends. _resource_create parses the entire
JSON body and returns one integer from it (_transport.py:426-480), discarding the rest silently.
Demonstrated with httpx.MockTransport under the real client: a POST answering 201 with a complete
16-field ticket record still yields bare 4242, and a PATCH answering 200 with the full updated record
yields None.

So the current signature cannot be cited as evidence about server behaviour. Open question worth one
preprod probe:
does the v2 POST body carry only id, or a fuller record? Live runs prove an integer id
is present (four create_* ids are round-tripped in integration_tests/); nobody has recorded the full
body.

Likewise, "re-reading would hide a second HTTP call behind a write" is not an invariant this codebase
holds -- create_kb_article already makes a v2 POST plus a v1 PUT behind one create-shaped name
(_article.py:89-121).

Recommendation: keep the primitives

The load-bearing reasons are:

  • 19 of GetTicket's 44 fields are server-assigned, so the fetch is real work a caller may not want
  • the read-back can fail independently of the write and destroy the id
  • callers already write the two-line composition in the docs

Costs if adopted

  • 12-13 methods, not one, and it cannot be made uniform -- create_item_plugin_field_row has no get_
    counterpart
  • _and_ appears in zero of 85 current method names, against a verb_noun house style
  • testing/tests/test_skill_references.py forces every new name into a SKILL.md
  • the composed helper has a failure mode the primitive lacks (write succeeds, read-back raises, id lost) --
    it would need create_kb_article's discipline of naming the new id in the error

Mechanically it is safe: a plain token rewrite for unasync, no mypy ignore needed, and
test_method_invocation.py:265-302 parametrises over every public name so coverage is automatic. Sphinx
needs no edit (api_reference.rst uses :members: :inherited-members:).

Filed for a decision, low priority.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions