This repository was archived by the owner on Jul 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
fix: scope schema-drift check to litigation cases #84
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,36 +1,70 @@ | ||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||
| from sqlalchemy import text | ||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||
| from sqlalchemy import text | ||||||||||||||||||||||||||
| from ngm.database.models import get_engine | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # A blank case_type only signals selector/schema drift for *litigation* cases. | ||||||||||||||||||||||||||
| # Non-litigation registrations (marriage, power-of-attorney, guardianship, | ||||||||||||||||||||||||||
| # adoption, death-declaration) are filed under a numeric case-number namespace | ||||||||||||||||||||||||||
| # (e.g. 082-02-0001) and legitimately carry no case_type. Litigation cases use | ||||||||||||||||||||||||||
| # an alphabetic namespace (CP, FN, CR, WO, C1, ...). We therefore only count | ||||||||||||||||||||||||||
| # blanks among alpha-coded rows, and fail on the *ratio* rather than an absolute | ||||||||||||||||||||||||||
| # count so the check scales with table size. | ||||||||||||||||||||||||||
| LITIGATION_ONLY = "split_part(case_number, '-', 2) ~ '[A-Za-z]'" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Fail if more than this fraction of in-scope litigation rows lack a case_type. | ||||||||||||||||||||||||||
| DRIFT_RATIO_THRESHOLD = 0.02 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def check(): | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def check(courts=None): | ||||||||||||||||||||||||||
| db_url = os.getenv("DATABASE_URL") | ||||||||||||||||||||||||||
| if not db_url: | ||||||||||||||||||||||||||
| print("DATABASE_URL not set") | ||||||||||||||||||||||||||
| sys.exit(1) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| where = [LITIGATION_ONLY] | ||||||||||||||||||||||||||
| params = {} | ||||||||||||||||||||||||||
| if courts: | ||||||||||||||||||||||||||
| where.append("court_identifier = ANY(:courts)") | ||||||||||||||||||||||||||
| params["courts"] = list(courts) | ||||||||||||||||||||||||||
| scope = " AND ".join(where) | ||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||
| where = [LITIGATION_ONLY] | |
| params = {} | |
| if courts: | |
| where.append("court_identifier = ANY(:courts)") | |
| params["courts"] = list(courts) | |
| scope = " AND ".join(where) | |
| where = [LITIGATION_ONLY, "created_at >= NOW() - INTERVAL '3 days'"] | |
| params = {} | |
| if courts: | |
| where.append("court_identifier = ANY(:courts)") | |
| params["courts"] = list(courts) | |
| scope = " AND ".join(where) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user passes an invalid court identifier (e.g., due to a typo like
supremee), the script currently queriescourt_identifier = ANY(['supremee']). Since no rows match,totalwill be0, and the script will print:Schema check skipped: no litigation rows in scope (courts=['supremee'])and exit with code
0(success).This silently skips the schema check instead of alerting the user that they provided an invalid court name.
Recommendation
Validate the provided court identifiers using the existing
is_valid_court_identifierutility before running the query.