Skip to content

Fix course instructor serialization with Koha REST context - #45

Open
nugged wants to merge 2 commits into
mainfrom
codex/fix-course-instructor-serialization
Open

nugged wants to merge 2 commits into
mainfrom
codex/fix-course-instructor-serialization

Conversation

@nugged

@nugged nugged commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Addresses #44.

Problem

CourseReservesController::_get_paged_results serialized result sets directly with:

$results->to_api()

That bypasses the request context supplied by Koha::REST::Plugin::Objects. In particular, Koha::Patron->to_api requires the authenticated user parameter.

This explains the data-dependent failure reported in #44:

  • no instructors: the empty result set serializes as [];
  • one or more instructors: patron serialization is invoked without user, raising Koha::Exceptions::MissingParameter and returning HTTP 500.

Change

Serialize paged course-reserve result sets through Koha's controller helper:

$c->objects->to_api($results)

The helper supplies the standard public, embed, strings, and user context. This fixes non-empty /instructors responses without introducing plugin-local serialization policy.

A separate commit records the fix under an Unreleased changelog section so release maintenance can adjust it independently.

Commits

  1. Use Koha REST serializer for course reserve results
    • functional one-line fix with the failure mechanism documented in the commit body;
  2. Document the course instructor serialization fix
    • changelog-only commit.

Test plan

  1. Request /api/v1/contrib/kohasuomi/instructors with no instructors and confirm HTTP 200 with [].
  2. Add a patron as instructor to an enabled course.
  3. Request the endpoint again and confirm HTTP 200 with the instructor's patron representation.
  4. Confirm pagination headers remain present.
  5. Smoke-test /courses, /departments, and /coursereserves, which share _get_paged_results.

Scope note

This PR does not alter the patron_id selected by /coursereserves. The controller currently sources it from course_instructors.borrowernumber; a concrete mismatching response is needed to determine whether #44 compares that internal patron identifier with userid/card number or exposes a separate join/cardinality defect.

Verification

The branch is exactly two commits ahead of main. The functional diff is one changed line; the other changed file is CHANGELOG.md.

Runtime tests were not run here because this repository has no test harness and the execution environment does not contain a Koha installation.

nugged added 2 commits August 31, 2026 11:20
Course reserve endpoints serialized result sets directly with
Koha::Objects->to_api. That bypassed the controller context supplied by
Koha::REST::Plugin::Objects, including the authenticated user.

Koha::Patron->to_api requires that user context, so /instructors
returned 500 as soon as the result set was non-empty while an empty set
still returned [].

Serialize through $c->objects->to_api so the standard public, embed,
strings and user context is passed to every result object.
Add an Unreleased changelog entry for the non-empty /instructors
failure without assigning the change to a release version prematurely.

Keeping this separate from the functional commit lets release
maintenance adjust or drop the note independently.
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.

1 participant