Conversation
…and lodgement_date
…ransformations for effective_to, listing_date, and lodgement_date
… categories in TEC adapter
…sformations with legacy mappings
…d optimize species/community resolution logic
…s_and_communities to conservation_status models
…remove unnecessary comments
…d improve fallback resolution logic
…ng in TPFL adapter
…ved date handling
…ased on Change Type) to alter the final actions displayed. Fixed a case difference between environments 'DeList' locally and 'Delist' in UAT. Code will now normalise code to lower case for comparisons.
… Change Type = DeList is selected. Added case normalisation for front end and backend comparisons
Comment on lines
+269
to
+279
| # We need to map this Taxonomy PK to the Species internal PK | ||
| species_pk = None | ||
| species_taxonomy_id = None | ||
|
|
||
| if row.get("species_id"): | ||
| # Pipeline transformed species_id to Taxonomy PK | ||
| species_taxonomy_id = row["species_id"] | ||
| species_pk = tax_to_species_pk_map.get(species_taxonomy_id) | ||
|
|
||
| # community_migrated_from_id pipeline should return Community PK or None | ||
| community_pk = row.get("community_migrated_from_id") |
There was a problem hiding this comment.
Bug: The migration silently creates ConservationStatus records with a null species_id if a Taxonomy record lacks an associated Species, bypassing model-level safeguards by using bulk_create().
Severity: MEDIUM
Suggested Fix
Before creating the ConservationStatus object, check if species_pk is None after the lookup. If it is, log an error and continue to the next row. This will prevent the creation of inconsistent records and restore the explicit validation behavior of the previous code.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: boranga/components/data_migration/handlers/conservation_status.py#L267-L279
Potential issue: The data migration handler for `ConservationStatus` resolves species
via a `taxonomy_id`. If a `taxonomy_id` from legacy data exists but has no corresponding
`Species` record, the `tax_to_species_pk_map.get()` call returns `None`. This `None`
value is then assigned to `species_pk` and used in the `ConservationStatus` object
creation. Because the handler uses `bulk_create()`, it bypasses the model's `save()`
method and its `assign_or_create_species()` safeguard. This results in the silent
creation of `ConservationStatus` records with a valid `species_taxonomy_id` but a `null`
`species_id`, leading to data inconsistency. The previous implementation would have
logged an error and skipped such records.
Did we get this right? 👍 / 👎 to inform future reviews.
xzzy
approved these changes
Feb 10, 2026
Collaborator
xzzy
left a comment
There was a problem hiding this comment.
Sensitivity check Completed
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.
Bug fixes for:
13979 | CS Delisting change 3/5: introduce a condition (based on Change Type) to alter the final actions displayed
13980 | CS Delisting change 4/5: validation required when Change Type = DeList is selected