Fix amendment lookup dropped by publication-date filter (#181)#182
Merged
andrew2net merged 1 commit intoJun 12, 2026
Merged
Conversation
Amendments, corrigendums and supplements carry no year on their own pubid identifier — the year lives on the underlying standard. When a publication-date filter is active, `get` routes through `find_match_by_date` -> `year_in_range?`, which bails on `return false if year.zero?`. For these references `hit_year` was 0, so they were excluded from every date-filtered query regardless of the filter year. This surfaced via Metanorma, which derives a publication-date filter from the citing document's `:copyright-year:`/`:created-date:` attributes: `ISO 32000-2:2020/DAM 1` resolved fine with `relaton fetch` but came back "Not found" when cited from such a document. Fall back to `hit.pubid.root.year`, which walks the full base chain (handling nested supplement/corrigendum-of-amendment), so the year of the underlying standard is used when the reference has none of its own. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 12, 2026
Contributor
|
@andrew2net The comment here is wrong:
A DRAFT Amendment/Corrigendum may or may not have a year attached.
An Amendment/Corrigendum/Supplement may or may not have a year attached.
|
Contributor
Author
|
@ronaldtse thanks for clarifying. This raises the following questions:
|
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.
Problem
Fixes #181. Citing a draft amendment such as
ISO 32000-2:2020/DAM 1from Metanorma logsNot foundand renders[NO INFORMATION AVAILABLE], even thoughrelaton fetch "ISO 32000-2:2020/DAM 1"returns full XML on the same machine.Root cause
Amendments, corrigendums and supplements carry no year on their own pubid identifier — the year lives on the underlying standard (
pubid.root.year, e.g.2020):When a publication-date filter is active,
Bibliography.getroutes throughfind_match_by_date→year_in_range?, which begins withreturn false if year.zero?. For these referenceshit_yearresolved to0(own yearnil, index:yearabsent), so they were excluded from every date-filtered query — regardless of the filter year (verified across 2019–2026, all "Not found").This only surfaces inside Metanorma because Metanorma derives a publication-date filter from the citing document's
:copyright-year:/:created-date:attributes.relaton fetchpasses no such filter, which is why the CLI worked. Reproduced end-to-end with Peter'smn-playgroundbuild on macOS; removing only those two attributes from the document flips the result toFound.Not a pubid-version, platform (Windows/Ruby 4), or stale-index issue — all ruled out.
Fixes
1. Year fallback (
hit_year). Fall back tohit.pubid.root.yearwhen the identifier's own year and the index:yearare both absent.rootwalks the full base chain (handling nested supplement / corrigendum-of-amendment), unlikebasewhich climbs only one level.2. Robustness guard (
fetch_and_check_date). The year fix lets amendments reachfetch_and_check_date. If the index references a data file that 404s,hit.itemreturns an item with no docidentifier and the method crashed onret.docidentifier.first.content. Guard against it so the candidate is skipped and the lookup degrades to "not found" instead of raising.Tests
"finds an amendment whose year lives on the base"— date filter +iso_32000_2_2020_dam_1cassette; fails before fix (nil), passes after."returns nil instead of raising when the data file fails to load"— locks the robustness guard.bibliography_spec.rbsuite green.Note on upstream data
While verifying end-to-end I found the relaton-data-iso
v2data files for this amendment (data/iso-32000-2-2020-dam-1.yaml) currently 404, after automated "update documents" commits on 2026-06-12 — the index still lists them. That's a separate data-side inconsistency; with the data present (as in the recorded cassette) this fix resolves the reference fully, and with it absent the second commit makes the lookup degrade cleanly instead of crashing.🤖 Generated with Claude Code