Skip to content

Prevent ontology term links being recreated on every update. Fixes #1270#1271

Merged
fbacall merged 1 commit into
masterfrom
ontology-term-link-fix
Apr 6, 2026
Merged

Prevent ontology term links being recreated on every update. Fixes #1270#1271
fbacall merged 1 commit into
masterfrom
ontology-term-link-fix

Conversation

@fbacall

@fbacall fbacall commented Mar 31, 2026

Copy link
Copy Markdown
Member

Summary of changes

  • Adds a setter method that discovers existing OntologyTermLinks and keeps those over creating new ones.

Motivation and context

Noticed the IDs of OntologyTermLink records were gigantic.

Checklist

  • I have read and followed the CONTRIBUTING guide.
  • I confirm that I have the authority necessary to make this contribution on behalf of its copyright owner and agree to license it to the TeSS codebase under the BSD license.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 aims to prevent OntologyTermLink records from being destroyed/recreated on every update by reusing existing links where possible, addressing unusually large link IDs (Fixes #1270).

Changes:

  • Adds a custom *_links= setter in HasOntologyTerms to preserve existing OntologyTermLinks when the assigned term URIs haven’t changed.
  • Introduces a regression test ensuring ontology term link records are not recreated when reassigning the same scientific topics, and that only genuinely changed topics result in new link records.

Reviewed changes

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

File Description
lib/has_ontology_terms.rb Overrides the association writer for ontology term link associations to keep matching existing links by term_uri instead of always replacing them with new records.
test/models/event_test.rb Adds a test verifying ontology term links aren’t recreated on repeated updates, and only changed terms produce new links.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/has_ontology_terms.rb
Comment thread test/models/event_test.rb
Comment on lines +795 to +798
end

assert_equal ontology_term_links, e.reload.ontology_term_links.to_a

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

This assertion compares arrays of ActiveRecord objects with an implicit ordering from the database. To avoid flaky tests across DB adapters or query plans, compare sorted IDs (or otherwise normalize ordering) rather than relying on to_a returning a stable order.

Copilot uses AI. Check for mistakes.
Comment thread lib/has_ontology_terms.rb
@fbacall
fbacall merged commit 97589bd into master Apr 6, 2026
15 checks passed
@fbacall
fbacall deleted the ontology-term-link-fix branch April 6, 2026 19:06
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