Skip to content

fix(texas): Importer fixes for #7145#7181

Merged
albertisfu merged 3 commits intomainfrom
morgan/7145-texas-importer-improvements
Apr 3, 2026
Merged

fix(texas): Importer fixes for #7145#7181
albertisfu merged 3 commits intomainfrom
morgan/7145-texas-importer-improvements

Conversation

@MorganBennetDev
Copy link
Copy Markdown
Contributor

Two fixes for errors encountered during Texas docket merging (see #7145):

  1. Add None check for workload transfer origin court ID in merge_texas_case_transfers. When texas_js_court_id_to_court_id returns None for unknown courts, skip the workload transfer with a warning instead of passing None to Court.objects.get().

  2. Wrap AttorneyOrganization.objects.create() in a savepoint in add_attorney. The enclosing add_parties_and_attorneys is @transaction.atomic, so an IntegrityError from a race condition on create() would abort the transaction. The recovery get() then failed with TransactionManagementError. The savepoint ensures only it rolls back, not the outer transaction.

Once all fixes have been added, I'll move this PR out of draft.

Deployment

This PR should:

  • skip-deploy (skips everything below)
    • skip-web-deploy
    • skip-celery-deploy
    • skip-cronjob-deploy
    • skip-daemon-deploy

…or in Texas imports (#7145)

Two fixes for errors encountered during Texas docket merging:

1. Add None check for workload transfer origin court ID in
   merge_texas_case_transfers. When texas_js_court_id_to_court_id
   returns None for unknown courts, skip the workload transfer with a
   warning instead of passing None to Court.objects.get().

2. Wrap AttorneyOrganization.objects.create() in a savepoint in
   add_attorney. The enclosing add_parties_and_attorneys is
   @transaction.atomic, so an IntegrityError from a race condition on
   create() would abort the transaction. The recovery get() then failed
   with TransactionManagementError. The savepoint ensures only it rolls
   back, not the outer transaction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@MorganBennetDev MorganBennetDev self-assigned this Apr 1, 2026
@MorganBennetDev MorganBennetDev moved this from To Do to In progress in Sprint (Web Team) Apr 1, 2026
@MorganBennetDev MorganBennetDev changed the title fix(corpus_importer): Guard unknown court IDs and fix transaction error in Texas imports fix(texas): Importer fixes for #7145 Apr 1, 2026
@MorganBennetDev
Copy link
Copy Markdown
Contributor Author

Returned MergeResult.unnecessary(None) instead of MergeResult.failed() when skipping imports, but I'd like to add a skipped field to MergeResult after the rewrite in #6988 is merged and log that at the end of the merger method. I'd also like to make the log better than "Something failed, oops." after that's merged (since we'll have the information to do so).

@MorganBennetDev MorganBennetDev marked this pull request as ready for review April 1, 2026 23:16
@MorganBennetDev MorganBennetDev moved this from In progress to To Do in Sprint (Web Team) Apr 1, 2026
with transaction.atomic():
org = AttorneyOrganization.objects.create(
**atty_org_info
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my understanding of the fix. Looks good to me.

sequenceDiagram
    participant P1 as Process 1
    participant DB as PostgreSQL
    participant P2 as Process 2

    P1->>DB: BEGIN (add_parties_and_attorneys @transaction.atomic)
    P1->>DB: AttorneyOrganization.objects.get(lookup_key="X")
    DB-->>P1: DoesNotExist

    Note over P2: Enter Villain
    P2->>DB: AttorneyOrganization.objects.create(lookup_key="X")
    DB-->>P2: OK ✓

    P1->>DB: SAVEPOINT (with transaction.atomic) ← fix
    P1->>DB: AttorneyOrganization.objects.create(lookup_key="X")
    DB-->>P1: IntegrityError (duplicate key)
    P1->>DB: ROLLBACK TO SAVEPOINT ← only savepoint is aborted
    Note over P1: Catches IntegrityError, retries get()
    P1->>DB: AttorneyOrganization.objects.get(lookup_key="X")
    DB-->>P1: OK ✓
    P1->>DB: COMMIT
Loading

@Brennan-Chesley-FLP
Copy link
Copy Markdown
Contributor

Though it conjures hilarious images of gluttony to see unnecessary(None) in the code and I hate to see it go for that reason, I agree that your follow up would make it a bit more obvious what's going on. Overall looks good to me.

Copy link
Copy Markdown
Contributor

@albertisfu albertisfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Merging!

Thank you.

@albertisfu albertisfu enabled auto-merge April 3, 2026 15:02
@albertisfu albertisfu merged commit bb67437 into main Apr 3, 2026
10 of 11 checks passed
@albertisfu albertisfu deleted the morgan/7145-texas-importer-improvements branch April 3, 2026 15:18
@github-project-automation github-project-automation bot moved this from To Do to Done in Sprint (Web Team) Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants