Skip to content

[Port to dtq-dev] fix(self-link): say what happened when the REST API reduces a page size - #1490

Merged
milanmajchrak merged 1 commit into
dtq-devfrom
934-fe/self-link-mismatch-causes
Aug 27, 2026
Merged

[Port to dtq-dev] fix(self-link): say what happened when the REST API reduces a page size#1490
milanmajchrak merged 1 commit into
dtq-devfrom
934-fe/self-link-mismatch-causes

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

References

Description

ensureSelfLink() uses one wording for every self link that differs from the url it was requested with, and it ends with "This could mean there's an issue with the REST endpoint". For a page size the API reduced that points at the wrong place: the API did what its contract says, the caller asked for a bigger page than it will serve.

Instructions for Reviewers

Why this comes after #1415: that PR normalized embed params and percent encoding on both sides and replaced the oversized page sizes with MAX_PAGE_SIZE at ten call sites. Now that nothing asks for an impossible page, a reduced page size means the caller was wrong, and the message can say so.

The request for '.../bundles?size=9999' asked for a page of 9999 elements, but the REST API served 1000. Ask for at most MAX_PAGE_SIZE elements

Changes:

  • isUnexpectedSelfLink() becomes selfLinkWarning(), returning the message to log or undefined, plus the getPageSize() / withoutPageSize() helpers.
  • The specific message applies only when the two urls are otherwise identical, so an accepted reduction cannot mask a wrong page or sort. Anything else keeps the generic message, including a page that came back larger than requested.
  • The code that rewrites _links.self is unchanged, so caching is unaffected.
  • Spec goes from 17 to 19 cases.

Left out of the upstream commit: nothing. What differs is the file around it — upstream main uses @dspace/* aliases and inject(APP_CONFIG) and a TestBed spec, none of which exist on 7.6.5.

How to test: temporarily change elementsPerPage: MAX_PAGE_SIZE to 9999 in findByItemAndName() in bundle-data.service.ts (line 84) and open an item page with the console open. Before the change it blames the REST endpoint, after it names the requested and the served size. Revert afterwards.

Checklist

  • My PR is created against dtq-dev (port of an upstream fix onto our 7.6.5 line).
  • My PR is small in size (2 files, +64/-23).
  • My PR follows all coding best practices based on the Code Conventions Guide.
  • My PR passes ESLint validation (0 errors; 1 warning on a pre-existing line, identical on dtq-dev).
  • My PR doesn't introduce circular dependencies — the npm script cannot run on Windows (pre-existing quoting bug in package.json); madge run directly reports none over 2995 files.
  • My PR includes TypeDoc comments for all new methods.
  • My PR passes all specs/tests and includes new/updated specs or tests (full suite 5510 SUCCESS; target spec 19 SUCCESS).
  • My PR aligns with Accessibility guidelines: no UI changes.
  • My PR uses i18n keys: nothing user facing, the only string is a console warning.
  • My PR includes details on how to test it.
  • No new libraries or dependencies.
  • If my PR fixes an issue ticket, I've linked them together.

Written with some help from Claude Code.

ensureSelfLink() logs one wording for every self link that differs from the url
it was requested with, and that wording ends with "This could mean there's an
issue with the REST endpoint". For a page size the API reduced, that points at
the wrong place: the API did exactly what its contract says, the caller asked
for a bigger page than it will ever serve. Whoever reads the console goes
looking at the backend for a frontend mistake.

Give that case its own message:

  The request for '.../bundles?size=9999' asked for a page of 9999 elements, but
  the REST API served 1000. Ask for at most MAX_PAGE_SIZE elements

It applies only when the two urls are otherwise identical, so an accepted
reduction cannot mask a wrong page or sort. Anything else keeps the generic
message, including a page that came back larger than requested.

This is the remaining half of the fix on dtq-dev. #1415 landed the rest - embed
params and percent encoding normalized on both sides, MAX_PAGE_SIZE next to
FindListOptions, and every oversized call site brought within it - so a reduced
page size now genuinely means a caller asked for something the API was never
going to serve, and the message can say so.

- src/app/core/data/dspace-rest-response-parsing.service.ts - replace
  isUnexpectedSelfLink() with selfLinkWarning(), which returns the message to
  log or undefined when there is nothing to report, and add the
  getPageSize()/withoutPageSize() helpers and the PAGE_SIZE_PARAM they match on.
  The self link is normalized either way, as before, so the url a response is
  cached under does not change - only whether and how we warn.
- src/app/core/data/dspace-rest-response-parsing.service.spec.ts - 17 cases to
  19. The reduced page size case now expects the specific wording; one new case
  pins that a reduced size is recognised alongside other params, another that a
  page differing as well falls back to the generic message.

Adapted to 7.6 from DSpace/dspace-angular PR 6083, commit 887ddec. The
9.x-only parts of that commit's file - the @dspace/* path aliases and the
inject(APP_CONFIG) refactor - are deliberately left out, which is also why the
spec keeps its plain constructor harness instead of upstream's TestBed. Same
change as #1448, which went to customer/jcu only.

Fixes dataquest-dev/dspace-customers#934

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@milanmajchrak milanmajchrak changed the title fix(self-link): say what happened when the API reduces a page size [Port to dtq-dev] fix(self-link): say what happened when the REST API reduces a page size Aug 27, 2026
@milanmajchrak
milanmajchrak requested a lite review from Copilot August 27, 2026 11:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines ensureSelfLink()’s console warning behavior in DspaceRestResponseParsingService so that when the REST API reduces a requested page size (per its contract), the warning explains the real cause (caller requested too many elements) instead of suggesting an endpoint bug.

Changes:

  • Replace isUnexpectedSelfLink() with selfLinkWarning() that returns a specific message for “only page size reduced” cases, or a generic mismatch warning otherwise.
  • Add page-size parsing helpers (getPageSize(), withoutPageSize()) to detect when size is the only difference.
  • Extend the spec suite to assert the new reduced-page-size warning behavior (17 → 19 cases).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/app/core/data/dspace-rest-response-parsing.service.ts Adds page-size detection and returns a more accurate warning when the API reduces the requested page size, keeping generic warnings for other mismatches.
src/app/core/data/dspace-rest-response-parsing.service.spec.ts Adds/adjusts test cases to verify the new warning message for reduced page sizes and fallback to the generic warning when other differences exist.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@milanmajchrak
milanmajchrak merged commit 51796ec into dtq-dev Aug 27, 2026
6 checks passed
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