Fix 500 when every wiki page link fails to resolve - #24770
Open
jtauschl wants to merge 2 commits into
Open
Conversation
When every link's identifier fails to resolve via the page-info query,
metadata ends up empty; enrich_models still tried to build a
LEFT JOIN (VALUES #{placeholders}) with zero placeholders, producing
the invalid SQL fragment "LEFT JOIN (VALUES )" and crashing with a
Postgres syntax error instead of returning the links with a nil title
(which is what happens for any individual link whose resolution
fails when at least one other link in the same request succeeds).
Return the relation directly with a NULL title column when metadata
is empty, matching the shape callers already get from the non-empty
path.
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
recheck |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Postgres syntax error (500) in the wiki page link metadata enrichment path when all page-link identifiers fail to resolve, by avoiding construction of an invalid LEFT JOIN (VALUES ) fragment and instead returning links with a NULL title column (matching the “partial failure” behavior).
Changes:
- Add an early return in
PageLinkMetadataService#enrich_modelsto selectNULL AS titlewhen the metadata list is empty. - Add a regression spec covering the “all links fail to resolve” scenario, asserting the service does not raise and returns all links with
niltitles.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| modules/wikis/app/services/wikis/page_link_metadata_service.rb | Returns a relation with a NULL title column when no metadata rows are available, preventing invalid SQL. |
| modules/wikis/spec/services/wikis/page_link_metadata_service_spec.rb | Adds regression coverage for the “all page links unresolvable” case (no crash, nil titles preserved). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+89
to
+94
| it "returns the relation without raising, instead of crashing on an empty VALUES clause" do | ||
| expect { service.call }.not_to raise_error | ||
|
|
||
| service_result = service.call | ||
| expect(service_result).to be_success | ||
| end |
service.call was invoked once inside expect { ... }.not_to raise_error
and again to capture the result -- the second call re-ran the same
service logic (a real, if idempotent, side effect) purely to get a
value the first call had already produced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
n/a
Summary
Fixes the crash described in OP-19928 (points 2 and 3 of that report -- point 1's original framing about identifier semantics has been corrected in a follow-up comment there and does not apply to this fix).
When every link's identifier fails to resolve via the page-info query,
metadataends up empty.enrich_modelsstill tried to build aLEFT JOIN (VALUES #{placeholders})with zero placeholders, producing the invalid SQL fragmentLEFT JOIN (VALUES )and crashing with a Postgres syntax error, instead of returning the links with a nil title (which is what already happens for any individual link whose resolution fails when at least one other link in the same request succeeds).Change
Return the relation directly with a
NULLtitle column whenmetadatais empty, matching the shape callers already get from the non-empty path.Test plan
GETon a work package with one unresolvable-identifier link returned 500; after the fix, it returns 200 with the link's title absent