-
Notifications
You must be signed in to change notification settings - Fork 11
Fix duplicate TaxaList names causing MultipleObjectsReturned #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ate names The TaxaList model allows multiple lists with the same name, but several places in the codebase use get_or_create(name=...) which fails with MultipleObjectsReturned when duplicates exist. This adds a new get_or_create_for_project() method that: - Scopes lookups to a specific project (or global lists if project=None) - Handles existing duplicates gracefully by returning the oldest one - Updates all callers (pipeline.py, import_taxa, update_taxa) to use it Also adds TODO comments to management commands about adding --project parameter support in the future. Co-Authored-By: Claude <[email protected]>
✅ Deploy Preview for antenna-ssec canceled.
|
✅ Deploy Preview for antenna-preview canceled.
|
📝 WalkthroughWalkthroughThe PR refactors taxa list creation across the codebase by introducing a new Changes
Sequence DiagramsequenceDiagram
participant Cmd as Command
participant QS as TaxaListQuerySet
participant DB as Database
Cmd->>QS: get_or_create_for_project(name, project=None)
alt project is None (Global List)
QS->>DB: Filter lists with no associated projects
DB-->>QS: Matching global list (if exists)
alt List exists
QS-->>Cmd: Return (existing_list, False)
else List not found
QS->>DB: Create new global TaxaList
DB-->>QS: New TaxaList instance
QS-->>Cmd: Return (new_list, True)
end
else project provided (Project-scoped List)
QS->>DB: Filter lists for specific project
DB-->>QS: Matching project-scoped list (if exists)
alt List exists
QS-->>Cmd: Return (existing_list, False)
else List not found
QS->>DB: Create new TaxaList and associate with project
DB-->>QS: New TaxaList instance
QS-->>Cmd: Return (new_list, True)
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Summary
TaxaListQuerySet.get_or_create_for_project()method to scope TaxaList lookups by projectpipeline.py,import_taxa,update_taxa) to use the new methodProblem
The
TaxaList.namefield has no unique constraint, but code was usingget_or_create(name=...)which fails withMultipleObjectsReturnedwhen duplicate names exist in the database.Solution
The new
get_or_create_for_project(name, project=None)method:project=None(global lists): finds lists with no project associationsproject=X: finds lists associated with that specific projectFollow-up needed
--projectparameter support to management commandsTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.