From 3149c42ab04186a05ac963b160aa9c9e5e629181 Mon Sep 17 00:00:00 2001 From: Karim El Jazzar Date: Thu, 27 Aug 2026 14:23:30 -0700 Subject: [PATCH 1/4] 34514 fix tasks load for legacy data with year 1 founding date --- .../resources/v2/business/business_tasks.py | 11 ++++++++++- .../unit/resources/v2/test_business_tasks.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/legal-api/src/legal_api/resources/v2/business/business_tasks.py b/legal-api/src/legal_api/resources/v2/business/business_tasks.py index 2e28b1bdb1..1b0aab2b93 100644 --- a/legal-api/src/legal_api/resources/v2/business/business_tasks.py +++ b/legal-api/src/legal_api/resources/v2/business/business_tasks.py @@ -151,7 +151,16 @@ def construct_task_list(business: Business): # noqa: PLR0915 tasks.append(task) order += 1 - if business.legal_type not in entity_types_no_ar and not business.in_liquidation: + # Skip AR todos when founding date is the COLIN year-1 sentinel / unknown. Without this, + # a sentinel founding_date of 0001-01-01 generates ~2000 AR todos and a multi-MB /tasks payload. + unknown_founding_date = ( + not business.founding_date or business.founding_date.year <= 1 + ) + if ( + business.legal_type not in entity_types_no_ar + and not business.in_liquidation + and not unknown_founding_date + ): # If this is the first calendar year since incorporation, there is no previous ar year. next_ar_year = (business.last_ar_year if business.last_ar_year else business.founding_date.year) + 1 diff --git a/legal-api/tests/unit/resources/v2/test_business_tasks.py b/legal-api/tests/unit/resources/v2/test_business_tasks.py index 2c04f942c7..b3eb906bdf 100644 --- a/legal-api/tests/unit/resources/v2/test_business_tasks.py +++ b/legal-api/tests/unit/resources/v2/test_business_tasks.py @@ -97,6 +97,25 @@ def test_get_tasks_no_filings(session, client, jwt): assert num_filings_owed == len(rv.json.get('tasks')) +def test_get_tasks_sentinel_founding_date_skips_ar(session, client, jwt): + """Assert COLIN year-1 sentinel founding date does not generate thousands of AR todos.""" + identifier = 'RLY0000004' + factory_business( + identifier, + founding_date=datetime(1, 1, 1, 8, 0, 0, tzinfo=UTC), + entity_type=Business.LegalTypes.COMP.value, + state=Business.State.ACTIVE, + ) + + rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) + assert rv.status_code == HTTPStatus.OK + ar_tasks = [ + t for t in rv.json.get('tasks') + if t.get('task', {}).get('todo', {}).get('header', {}).get('name') == 'annualReport' + ] + assert ar_tasks == [] + + def test_get_tasks_next_year(session, client, jwt): """Assert that one todo item is returned in the calendar year following incorporation.""" identifier = 'CP7654321' From bea28cafa7137341dfbdb211df3451b75dfc55eb Mon Sep 17 00:00:00 2001 From: Karim El Jazzar Date: Thu, 27 Aug 2026 14:29:57 -0700 Subject: [PATCH 2/4] comment --- legal-api/src/legal_api/resources/v2/business/business_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legal-api/src/legal_api/resources/v2/business/business_tasks.py b/legal-api/src/legal_api/resources/v2/business/business_tasks.py index 1b0aab2b93..9899419a16 100644 --- a/legal-api/src/legal_api/resources/v2/business/business_tasks.py +++ b/legal-api/src/legal_api/resources/v2/business/business_tasks.py @@ -151,7 +151,7 @@ def construct_task_list(business: Business): # noqa: PLR0915 tasks.append(task) order += 1 - # Skip AR todos when founding date is the COLIN year-1 sentinel / unknown. Without this, + # Skip AR todos when founding date is the COLIN year 0001 (for legacy data like railways). Without this, # a sentinel founding_date of 0001-01-01 generates ~2000 AR todos and a multi-MB /tasks payload. unknown_founding_date = ( not business.founding_date or business.founding_date.year <= 1 From 83f68d05fce12bcf6eafcd387643b86d7f6171d1 Mon Sep 17 00:00:00 2001 From: Karim El Jazzar Date: Thu, 27 Aug 2026 14:48:28 -0700 Subject: [PATCH 3/4] fix unit test --- legal-api/tests/unit/resources/v2/test_business_tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legal-api/tests/unit/resources/v2/test_business_tasks.py b/legal-api/tests/unit/resources/v2/test_business_tasks.py index b3eb906bdf..24dc268afb 100644 --- a/legal-api/tests/unit/resources/v2/test_business_tasks.py +++ b/legal-api/tests/unit/resources/v2/test_business_tasks.py @@ -99,7 +99,7 @@ def test_get_tasks_no_filings(session, client, jwt): def test_get_tasks_sentinel_founding_date_skips_ar(session, client, jwt): """Assert COLIN year-1 sentinel founding date does not generate thousands of AR todos.""" - identifier = 'RLY0000004' + identifier = 'BC1234567' factory_business( identifier, founding_date=datetime(1, 1, 1, 8, 0, 0, tzinfo=UTC), @@ -113,7 +113,7 @@ def test_get_tasks_sentinel_founding_date_skips_ar(session, client, jwt): t for t in rv.json.get('tasks') if t.get('task', {}).get('todo', {}).get('header', {}).get('name') == 'annualReport' ] - assert ar_tasks == [] + assert len(ar_tasks) == 0 def test_get_tasks_next_year(session, client, jwt): From 260707bc7be2b830ce51e0681e9aa023065b24ac Mon Sep 17 00:00:00 2001 From: Karim El Jazzar Date: Thu, 27 Aug 2026 15:08:04 -0700 Subject: [PATCH 4/4] fixed SC issue --- legal-api/tests/unit/resources/v2/test_business_tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legal-api/tests/unit/resources/v2/test_business_tasks.py b/legal-api/tests/unit/resources/v2/test_business_tasks.py index 24dc268afb..d7e21095a6 100644 --- a/legal-api/tests/unit/resources/v2/test_business_tasks.py +++ b/legal-api/tests/unit/resources/v2/test_business_tasks.py @@ -94,7 +94,7 @@ def test_get_tasks_no_filings(session, client, jwt): rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK - assert num_filings_owed == len(rv.json.get('tasks')) + assert len(rv.json.get('tasks')) == num_filings_owed def test_get_tasks_sentinel_founding_date_skips_ar(session, client, jwt): @@ -126,7 +126,7 @@ def test_get_tasks_next_year(session, client, jwt): rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier)) assert rv.status_code == HTTPStatus.OK - assert 1 == len(rv.json.get('tasks')) + assert len(rv.json.get('tasks')) == 1 def test_bcorps_get_tasks_no_filings(session, client, jwt):