fix(species): guard against present-but-null external avatar URL#610
Open
meadowspace-apps wants to merge 1 commit intoMDeLuise:mainfrom
Open
fix(species): guard against present-but-null external avatar URL#610meadowspace-apps wants to merge 1 commit intoMDeLuise:mainfrom
meadowspace-apps wants to merge 1 commit intoMDeLuise:mainfrom
Conversation
`_loadExternal` checked `externalAvatarUrl.present` before dereferencing
`externalAvatarUrl.value!`, but drift considers a Value.present when it
was set, even if the contained value is null. FloraCodex returns
species with a null `image_url` often enough (e.g. many algae and
obscure genera) that this would throw:
type 'Null' is not a subtype of type 'Null' in type cast
(internally: "Null check operator used on a null value")
Add an explicit null check alongside `.present` so species with no
image simply load without their avatar.
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.
Hey Plant-it community!
This fixes a "null check operator used on a null value" crash that happens when opening the detail view for certain external species — one of the reproducible failure paths encountered while working through #589.
What's new?
In `ViewSpeciesViewModel._loadExternal`, the check `externalAvatarUrl.present` gated a dereference via `.value!`. Drift's `.present` is true whenever a `Value` was explicitly constructed — including `Value(null)`. For species with no `image_url` from FloraCodex, `externalAvatarUrl.value` is null but `.present` is still true, so the `!` threw.
Add an explicit `!= null` check alongside `.present` before the dereference.
Why is it important?
FloraCodex returns `image_url: null` for a meaningful portion of its catalogue (many algae, marine species, obscure genera — easy to hit from a casual "rose" search). Before this change, tapping any such species threw a null-check exception and the user saw a generic "null check operator used on a null value" error instead of the detail page. No image appears on the detail page either way; with the fix, the page just opens without an avatar.
How to Use?
No behavior change for species that do have an image. Species without an image now render their detail screen correctly instead of crashing.
Notes
Refs #589