Fix filter_* FK violation and add flux/filter consistency check - #149
Merged
Conversation
… consistency check Missing filter_* values (NaN from masked ecsv columns, or empty strings from CSV columns read with keep_default_na=False) were only normalized to None in the uploader-specific target code path. Any other insert path (fluxstd, sky, user_pointing, and target without --from-uploader) went through add_backref_values, which had no such normalization, so a bare NaN was sent to the database and coerced to the literal string "NaN", violating the filter_name foreign key constraint. Centralize the normalization in add_backref_values so it covers every insert path, and add check_filter_flux_consistency to reject rows where a flux value is present but its filter is missing, since that combination is not physically meaningful. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
add_backref_valuesnow normalizesfilter_*columns (NaN or empty string →None) for every insert path (fluxstd,sky,user_pointing, andtargetwithout--from-uploader), not just the uploader-specifictargetpath. This was causingKey (filter_g/i)=(NaN) is not present in table "filter_name"errors when a bare NaN got serialized to the literal string"NaN"by the database driver.u/v, which the old uploader-only code was missing.check_filter_flux_consistency, which raises aValueErrorif a row has a flux (or flux error) value for a band whose filter is missing — a flux measurement without a known filter is not physically meaningful.Test plan
uv run pytest tests --ignore=tests/integrationtarget_bc3a0193fa593b7c.ecsv): filter_g/filter_i NaNs now normalize toNonewith no leftoverNaNfloats, and the file passes the new consistency check without false positives.🤖 Generated with Claude Code