Skip to content

Commit

Permalink
fix(recap): Simplified PACER court validation queries
Browse files Browse the repository at this point in the history
  • Loading branch information
albertisfu committed Jan 7, 2025
1 parent f68adfc commit dfee2d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
34 changes: 12 additions & 22 deletions cl/recap/api_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def validate(self, attrs):
UPLOAD_TYPE.CASE_QUERY_RESULT_PAGE,
]:
# These are district or bankruptcy court dockets. Is the court valid?
court_ids = Court.federal_courts.district_or_bankruptcy_pacer_courts().values_list(
"pk", flat=True
court_ids = (
Court.federal_courts.district_or_bankruptcy_pacer_courts()
)
if attrs["court"].pk not in court_ids:
if not court_ids.filter(pk=attrs["court"].pk).exists():
raise ValidationError(
"%s is not a district or bankruptcy court ID. Did you "
"mean to use the upload_type for appellate dockets?"
Expand All @@ -108,11 +108,9 @@ def validate(self, attrs):
if attrs["upload_type"] == UPLOAD_TYPE.CLAIMS_REGISTER:
# Only allowed on bankruptcy courts
bankruptcy_court_ids = (
Court.federal_courts.bankruptcy_pacer_courts().values_list(
"pk", flat=True
)
Court.federal_courts.bankruptcy_pacer_courts()
)
if attrs["court"].pk not in bankruptcy_court_ids:
if not bankruptcy_court_ids.filter(pk=attrs["court"].pk).exists():
raise ValidationError(
"%s is not a bankruptcy court ID. Only bankruptcy cases "
"should have claims registry pages." % attrs["court"]
Expand All @@ -127,12 +125,8 @@ def validate(self, attrs):
UPLOAD_TYPE.APPELLATE_CASE_QUERY_RESULT_PAGE,
]:
# Appellate court dockets. Is the court valid?
appellate_court_ids = (
Court.federal_courts.appellate_pacer_courts().values_list(
"pk", flat=True
)
)
if attrs["court"].pk not in appellate_court_ids:
appellate_court_ids = Court.federal_courts.appellate_pacer_courts()
if not appellate_court_ids.filter(pk=attrs["court"].pk).exists():
raise ValidationError(
"%s is not an appellate court ID. Did you mean to use the "
"upload_type for district dockets?" % attrs["court"]
Expand Down Expand Up @@ -203,11 +197,8 @@ def validate(self, attrs):
mail = attrs["mail"]
receipt = attrs["receipt"]

all_court_ids = Court.federal_courts.all_pacer_courts().values_list(
"pk", flat=True
)

if court_id not in all_court_ids:
all_court_ids = Court.federal_courts.all_pacer_courts()
if not all_court_ids.filter(pk=court_id).exists():
raise ValidationError(
f"{attrs['court'].pk} is not a PACER court ID."
)
Expand Down Expand Up @@ -274,10 +265,9 @@ class Meta:

def validate(self, attrs):
# Is it a good court value?
valid_court_ids = Court.federal_courts.district_or_bankruptcy_pacer_courts().values_list(
"pk", flat=True
valid_court_ids = (
Court.federal_courts.district_or_bankruptcy_pacer_courts()
)

if (
attrs.get("court")
or attrs.get("docket")
Expand All @@ -293,7 +283,7 @@ def validate(self, attrs):
if attrs.get("court")
else attrs["docket"].court_id
)
if court_id not in valid_court_ids:
if not valid_court_ids.filter(pk=court_id).exists():
raise ValidationError(f"Invalid court id: {court_id}")

# Docket validations
Expand Down
11 changes: 2 additions & 9 deletions cl/recap/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,15 +763,8 @@ async def find_subdocket_pdf_rds(
pq.pk
] # Add the original pq to the list of pqs to process

appellate_court_ids = [
court_pk
async for court_pk in (
Court.federal_courts.appellate_pacer_courts().values_list(
"pk", flat=True
)
)
]
if pq.court_id in appellate_court_ids:
appellate_court_ids = Court.federal_courts.appellate_pacer_courts()
if await appellate_court_ids.filter(pk=pq.court_id).aexists():
# Abort the process for appellate documents. Subdockets cannot be found
# in appellate cases.
return pqs_to_process_pks
Expand Down

0 comments on commit dfee2d5

Please sign in to comment.