From 578452fa1c6c581fdc03a2277fb671e3f2694424 Mon Sep 17 00:00:00 2001 From: ttys0dev <126845556+ttys0dev@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:59:36 -0700 Subject: [PATCH] Make ProcessingQueue document_number a CharField to match RECAPDocument Leading zeros are significant so we shouldn't use BigIntegerField. --- cl/recap/api_serializers.py | 8 ++++++ ...3_alter_processingqueue_document_number.py | 26 +++++++++++++++++++ ..._alter_processingqueue_document_number.sql | 9 +++++++ cl/recap/models.py | 4 +-- cl/recap/tasks.py | 6 +---- cl/recap/tests.py | 2 +- 6 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 cl/recap/migrations/0013_alter_processingqueue_document_number.py create mode 100644 cl/recap/migrations/0013_alter_processingqueue_document_number.sql diff --git a/cl/recap/api_serializers.py b/cl/recap/api_serializers.py index 9d3cd6f463..6835f9ed1e 100644 --- a/cl/recap/api_serializers.py +++ b/cl/recap/api_serializers.py @@ -1,3 +1,5 @@ +import re + from django.contrib.auth.models import User from juriscraper.lib.exceptions import PacerLoginException from rest_framework import serializers @@ -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, diff --git a/cl/recap/migrations/0013_alter_processingqueue_document_number.py b/cl/recap/migrations/0013_alter_processingqueue_document_number.py new file mode 100644 index 0000000000..28ec45c70d --- /dev/null +++ b/cl/recap/migrations/0013_alter_processingqueue_document_number.py @@ -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, + ), + ] diff --git a/cl/recap/migrations/0013_alter_processingqueue_document_number.sql b/cl/recap/migrations/0013_alter_processingqueue_document_number.sql new file mode 100644 index 0000000000..88d4e564df --- /dev/null +++ b/cl/recap/migrations/0013_alter_processingqueue_document_number.sql @@ -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; diff --git a/cl/recap/models.py b/cl/recap/models.py index c3a570f4b8..d6b15f526d 100644 --- a/cl/recap/models.py +++ b/cl/recap/models.py @@ -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 " diff --git a/cl/recap/tasks.py b/cl/recap/tasks.py index 67dab8727c..8ae573c395 100644 --- a/cl/recap/tasks.py +++ b/cl/recap/tasks.py @@ -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. diff --git a/cl/recap/tests.py b/cl/recap/tests.py index 36d0f357c8..164be92c5f 100644 --- a/cl/recap/tests.py +++ b/cl/recap/tests.py @@ -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()