Skip to content

Commit

Permalink
Make ProcessingQueue document_number a CharField to match RECAPDocument
Browse files Browse the repository at this point in the history
Leading zeros are significant so we shouldn't use BigIntegerField.
  • Loading branch information
ttys0dev committed Nov 18, 2023
1 parent 4204782 commit 578452f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
8 changes: 8 additions & 0 deletions cl/recap/api_serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from django.contrib.auth.models import User
from juriscraper.lib.exceptions import PacerLoginException
from rest_framework import serializers
Expand Down Expand Up @@ -148,6 +150,12 @@ def validate(self, attrs):
"document_number fields completed."
)

if not re.match("^[0-9]*$", attrs.get("document_number")):
raise ValidationError(
"Uploaded PDFs document_number field can only contain "
"numbers."
)

if attrs["upload_type"] not in [
UPLOAD_TYPE.PDF,
UPLOAD_TYPE.APPELLATE_CASE_QUERY_RESULT_PAGE,
Expand Down
26 changes: 26 additions & 0 deletions cl/recap/migrations/0013_alter_processingqueue_document_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.7 on 2023-11-18 02:51

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"recap",
"0012_rename_fjcintegrateddatabase_district_docket_number_recap_fjcin_distric_731c7b_idx",
),
]

operations = [
migrations.AlterField(
model_name="processingqueue",
name="document_number",
field=models.CharField(
blank=True,
default="",
help_text="The docket entry number for the document.",
max_length=32,
),
preserve_default=False,
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BEGIN;
--
-- Alter field document_number on processingqueue
--
ALTER TABLE "recap_processingqueue" ALTER COLUMN "document_number" TYPE varchar(32) USING "document_number"::varchar(32), ALTER COLUMN "document_number" SET DEFAULT '';
UPDATE "recap_processingqueue" SET "document_number" = '' WHERE "document_number" IS NULL; SET CONSTRAINTS ALL IMMEDIATE;
ALTER TABLE "recap_processingqueue" ALTER COLUMN "document_number" SET NOT NULL;
ALTER TABLE "recap_processingqueue" ALTER COLUMN "document_number" DROP DEFAULT;
COMMIT;
4 changes: 2 additions & 2 deletions cl/recap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ class ProcessingQueue(AbstractDateTimeModel):
blank=True,
db_index=True,
)
document_number = models.BigIntegerField(
document_number = models.CharField(
help_text="The docket entry number for the document.",
max_length=32,
blank=True,
null=True,
)
attachment_number = models.SmallIntegerField(
help_text="If the file is an attachment, the number is the attachment "
Expand Down
6 changes: 1 addition & 5 deletions cl/recap/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,7 @@ async def process_recap_pdf(pk):
)
break

# document_number field is a CharField in RECAPDocument and a
# BigIntegerField in ProcessingQueue. To prevent the ES signal
# processor fields tracker from detecting it as a value change, it should
# be converted to a string.
rd.document_number = str(pq.document_number)
rd.document_number = pq.document_number
rd.attachment_number = pq.attachment_number

# Do the file, finally.
Expand Down
2 changes: 1 addition & 1 deletion cl/recap/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_uploading_a_pdf(self, mock):

j = json.loads(r.content)
self.assertEqual(j["court"], self.court.id)
self.assertEqual(j["document_number"], 1)
self.assertEqual(j["document_number"], "1")
self.assertEqual(j["pacer_case_id"], "asdf")
mock.assert_called()

Expand Down

0 comments on commit 578452f

Please sign in to comment.