Skip to content

Commit

Permalink
Update some django specific dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ttys0dev committed Dec 5, 2023
1 parent 34bd38b commit f1801da
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 308 deletions.
2 changes: 1 addition & 1 deletion cl/audio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Audio(AbstractDateTimeModel):
case_name_full = models.TextField(
help_text="The full name of the case", blank=True
)
panel = models.ManyToManyField(
panel = models.ManyToManyField( # type: ignore[var-annotated]
Person,
help_text="The judges that heard the oral arguments",
related_name="oral_argument_panel_members",
Expand Down
36 changes: 27 additions & 9 deletions cl/corpus_importer/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
ReadTimeout,
RequestException,
)
from requests.packages.urllib3.exceptions import ReadTimeoutError
from rest_framework.renderers import JSONRenderer
from rest_framework.status import (
HTTP_400_BAD_REQUEST,
HTTP_403_FORBIDDEN,
HTTP_500_INTERNAL_SERVER_ERROR,
HTTP_504_GATEWAY_TIMEOUT,
)
from urllib3.exceptions import ReadTimeoutError

from cl.alerts.tasks import enqueue_docket_alert, send_alert_and_webhook
from cl.audio.models import Audio
Expand Down Expand Up @@ -597,7 +597,7 @@ def get_and_process_free_pdf(
rd.pk, result.pacer_case_id, result.pacer_doc_id, cookies
)
except HTTPError as exc:
if exc.response.status_code in [
if exc.response and exc.response.status_code in [
HTTP_500_INTERNAL_SERVER_ERROR,
HTTP_504_GATEWAY_TIMEOUT,
]:
Expand All @@ -611,14 +611,22 @@ def get_and_process_free_pdf(
return None
logger.info(f"{msg} Retrying.")
raise self.retry(exc=exc)
else:
elif exc.response:
msg = (
f"Ran into unknown HTTPError while getting PDF: "
f"{exc.response.status_code}. Aborting."
)
logger.error(msg)
self.request.chain = None
return None
else:
msg = (
f"Ran into unknown HTTPError while getting PDF: "
f"{str(exc)}. Aborting."
)
logger.error(msg)
self.request.chain = None
return None
except PacerLoginException as exc:
msg = "PacerLoginException while getting free docs."
logger.info(f"{msg} Retrying.")
Expand Down Expand Up @@ -806,7 +814,7 @@ def upload_to_ia(
return None
raise self.retry(exc=exc)
except HTTPError as exc:
if exc.response.status_code in [
if exc.response and exc.response.status_code in [
HTTP_403_FORBIDDEN, # Can't access bucket, typically.
HTTP_400_BAD_REQUEST, # Corrupt PDF, typically.
]:
Expand Down Expand Up @@ -1447,19 +1455,24 @@ def get_attachment_page_by_rd(
try:
att_report = get_att_report_by_rd(rd, cookies)
except HTTPError as exc:
if exc.response.status_code in [
if exc.response and exc.response.status_code in [
HTTP_500_INTERNAL_SERVER_ERROR,
HTTP_504_GATEWAY_TIMEOUT,
]:
logger.warning(
"Ran into HTTPError: %s. Retrying.", exc.response.status_code
)
raise self.retry(exc)
else:
elif exc.response:
msg = "Ran into unknown HTTPError. %s. Aborting."
logger.error(msg, exc.response.status_code)
self.request.chain = None
return None
else:
msg = "Ran into unknown HTTPError. %s. Aborting."
logger.error(msg, str(exc))
self.request.chain = None
return None
except requests.RequestException as exc:
logger.warning("Unable to get attachment page for %s", rd)
raise self.retry(exc=exc)
Expand Down Expand Up @@ -2040,22 +2053,27 @@ def get_pacer_doc_id_with_show_case_doc_url(
logger.info(f"{msg} Retrying.", rd)
raise self.retry(exc=exc)
except HTTPError as exc:
status_code = exc.response.status_code
if status_code in [
if exc.response and exc.response.status_code in [
HTTP_500_INTERNAL_SERVER_ERROR,
HTTP_504_GATEWAY_TIMEOUT,
]:
status_code = exc.response.status_code
msg = "Got HTTPError with status code %s."
if last_try:
logger.error(f"{msg} Aborting.", status_code)
return

logger.info(f"{msg} Retrying", status_code)
raise self.retry(exc)
else:
elif exc.response:
status_code = exc.response.status_code
msg = "Ran into unknown HTTPError. %s. Aborting."
logger.error(msg, status_code)
return
else:
msg = "Ran into unknown HTTPError. %s. Aborting."
logger.error(msg, str(exc))
return
try:
pacer_doc_id = report.data
except ParsingException:
Expand Down
8 changes: 4 additions & 4 deletions cl/lib/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.conf import settings
from django.core.files.storage import FileSystemStorage, Storage
from storages.backends.s3boto3 import S3Boto3Storage, S3ManifestStaticStorage
from storages.backends.s3 import S3ManifestStaticStorage, S3Storage


def clobbering_get_name(
Expand Down Expand Up @@ -54,7 +54,7 @@ def get_name_by_incrementing(
return name


class AWSMediaStorage(S3Boto3Storage):
class AWSMediaStorage(S3Storage):
"""Implements AWS file system storage with a few overrides"""

location = ""
Expand Down Expand Up @@ -92,11 +92,11 @@ class SubDirectoryS3ManifestStaticStorage(S3ManifestStaticStorage):
manifest_strict = False


class RecapEmailSESStorage(S3Boto3Storage):
class RecapEmailSESStorage(S3Storage):
bucket_name = "recap.email"


class S3PrivateUUIDStorage(S3Boto3Storage):
class S3PrivateUUIDStorage(S3Storage):
"""Implements a UUID file system storage.
Useful when you don't care what the name of the file is, but you want it to
Expand Down
2 changes: 1 addition & 1 deletion cl/settings/third_party/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"default": {
"hosts": ELASTICSEARCH_DSL_HOST,
"http_auth": (ELASTICSEARCH_USER, ELASTICSEARCH_PASSWORD),
"use_ssl": True,
"scheme": "https",
"verify_certs": False,
"ca_certs": ELASTICSEARCH_CA_CERT,
"timeout": ELASTICSEARCH_TIMEOUT,
Expand Down
Loading

0 comments on commit f1801da

Please sign in to comment.