Skip to content

fix(trees): handle synonymization in save#8085

Draft
grantfitzsimmons wants to merge 3 commits into
mainfrom
issue-6810
Draft

fix(trees): handle synonymization in save#8085
grantfitzsimmons wants to merge 3 commits into
mainfrom
issue-6810

Conversation

@grantfitzsimmons
Copy link
Copy Markdown
Member

Fixes #6810

Fixes an issue where Determination.preferredTaxon didn't update when a Taxon's Accepted/Preferred taxon is changed via the Taxon form or API. Changes make all code-paths that change AcceptedID behave like the TreeViewer synonymize/desynonymize action.

By handling AcceptedID changes at the model layer, any code path that updates a Taxon's AcceptedID (UI form, API) will trigger the same Determination and child updates. This prevents the stale PreferredTaxon values previously seen in queries.

Root Cause

  • The tree synonymize/desynonymize flow (extras.synonymize() / desynonymize()) updated Determination.preferredTaxon, but direct updates to a Taxon's AcceptedID (e.g., via the Taxon form) only saved the Taxon record and did not propagate the change to Determinations or accepted children.

Currently working on handling the collection preferences for synonyms

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add automated tests

Testing instructions

  • On main, create a determination for Taxon A, set A.AcceptedTaxonB via the Taxon form, then confirm Determination.preferredTaxon still points to A until the determination is manually edited.
  • On the issue-6810 branch:
    • Create a determination for Taxon A where preferredTaxon = A.
    • Update A.acceptedTaxon = B and save.
    • Confirm Determination.preferredTaxon now equals B.
  • Desynonymize:
    • Set A.acceptedTaxon = None and save.
    • Confirm Determination.preferredTaxon equals the Determination.taxon (A).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 62b59ff2-2c8a-4154-a06a-7dc2f1bbd236

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-6810

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

try:
old_taxon = Taxon.objects.get(pk=self.pk)
old_accepted_id = old_taxon.acceptedtaxon_id
except Taxon.DoesNotExist:

# Update Determinations where this Taxon is already the preferred taxon
# Use lazy import to avoid circular import issues (same pattern as extras.py)
from specifyweb.specify.models import Determination

# Update Determinations where this Taxon is the preferred taxon
# to use themselves as the preferred taxon
from specifyweb.specify.models import Determination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋Back Log

Development

Successfully merging this pull request may close these issues.

Determinations do not update properly when Preferred Taxon changes

2 participants