Skip to content

Commit

Permalink
Merge pull request #4797 from freelawproject/4430-tweak-find-docket-o…
Browse files Browse the repository at this point in the history
…bject

4430 Tweak find_docket_object to match existing dockets with no pacer_case_id
  • Loading branch information
mlissner authored Dec 11, 2024
2 parents d8ade2e + c978887 commit 3c80142
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cl/recap/mergers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ async def find_docket_object(
"pacer_case_id": pacer_case_id,
"docket_number_core": docket_number_core,
},
# Appellate docket uploads usually include a pacer_case_id.
# Therefore, include the following lookup to attempt matching
# existing dockets without a pacer_case_id using docket_number_core
# to avoid creating duplicated dockets.
{
"pacer_case_id": None,
"docket_number_core": docket_number_core,
},
{"pacer_case_id": pacer_case_id},
]
if docket_number_core and not pacer_case_id:
Expand Down Expand Up @@ -362,6 +370,7 @@ async def update_docket_metadata(
d = update_case_names(d, docket_data["case_name"])
await mark_ia_upload_needed(d, save_docket=False)
d.docket_number = docket_data["docket_number"] or d.docket_number
d.pacer_case_id = d.pacer_case_id or docket_data.get("pacer_case_id")
d.date_filed = docket_data.get("date_filed") or d.date_filed
d.date_last_filing = (
docket_data.get("date_last_filing") or d.date_last_filing
Expand Down
73 changes: 73 additions & 0 deletions cl/recap/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7988,6 +7988,17 @@ def setUpTestData(cls):
case_name="Barton v. State", docket_number="3:17-mj-01477"
)

cls.docket_data_appellate = RECAPEmailDocketDataFactory(
case_name="Wright v. State Updated",
docket_number="20-10394",
pacer_case_id="67653",
)
cls.docket_data_appellate_no_case_id = RECAPEmailDocketDataFactory(
case_name="Wright v. State Updated",
docket_number="20-10394",
pacer_case_id=None,
)

def test_case_id_and_docket_number_core_lookup(self):
"""Confirm if lookup by pacer_case_id and docket_number_core works
properly.
Expand Down Expand Up @@ -8393,6 +8404,68 @@ def test_avoid_lookup_by_docket_number_components(self):
# selected instead.
self.assertEqual(docket_matched.pk, oldest_d_1.pk)

def test_avoid_duplicating_dockets_with_no_pacer_case_id(self):
"""Confirm we can match an existing docket with no pacer_case_id by
docket_number_core when lookup includes a pacer_case_id.
"""

d_1 = DocketFactory(
case_name="Wright v. State",
docket_number="20-10394",
court=self.court_appellate,
source=Docket.RECAP,
pacer_case_id=None,
)
self.assertEqual(Docket.objects.all().count(), 5)

# Lookup includes pacer_case_id
d_lookup = async_to_sync(find_docket_object)(
self.court_appellate.pk,
self.docket_data_appellate["pacer_case_id"],
self.docket_data_appellate["docket_number"],
None,
None,
None,
)

async_to_sync(update_docket_metadata)(
d_lookup, self.docket_data_appellate
)
d_lookup.save()

# Confirm that no new docket was created
self.assertEqual(Docket.objects.all().count(), 5)
# Confirm that the docket was properly matched and the pacer_case_id
# was updated.
self.assertEqual(d_lookup.id, d_1.id)
d_1.refresh_from_db()
self.assertEqual(
d_1.pacer_case_id, self.docket_data_appellate["pacer_case_id"]
)

# Now lookup again with no pacer_case_id.
d_lookup = async_to_sync(find_docket_object)(
self.court_appellate.pk,
self.docket_data_appellate_no_case_id["pacer_case_id"],
self.docket_data_appellate_no_case_id["docket_number"],
None,
None,
None,
)

async_to_sync(update_docket_metadata)(
d_lookup, self.docket_data_appellate_no_case_id
)
d_lookup.save()

# The docket should be properly matched.
self.assertEqual(Docket.objects.all().count(), 5)
self.assertEqual(d_lookup.id, d_1.id)
d_1.refresh_from_db()
self.assertEqual(
d_1.pacer_case_id, self.docket_data_appellate["pacer_case_id"]
)


class CleanUpDuplicateAppellateEntries(TestCase):
"""Test clean_up_duplicate_appellate_entries method that finds and clean
Expand Down

0 comments on commit 3c80142

Please sign in to comment.