Skip to content

Commit c34970c

Browse files
fix(CalendarDatesMergeLineContext): Fix ref integrity errors
1 parent 515db2d commit c34970c

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/main/java/com/conveyal/datatools/manager/jobs/feedmerge/CalendarDatesMergeLineContext.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ private boolean checkCalendarDatesIds(FieldContext fieldContext) throws IOExcept
5656
boolean shouldSkipRecord = false;
5757
if (job.mergeType.equals(SERVICE_PERIOD)) {
5858
// Drop any calendar_dates.txt records from the existing feed for dates that are
59-
// not before the first date of the future feed.
59+
// not before the first date of the future feed,
60+
// or for corresponding calendar entries that have been dropped.
6061
LocalDate date = getCsvDate("date");
62+
String calendarKey = getTableScopedValue(Table.CALENDAR, keyValue);
6163
if (
62-
isHandlingActiveFeed() && !isBeforeFutureFeedStartDate(date)
64+
isHandlingActiveFeed() &&
65+
(
66+
job.mergeFeedsResult.skippedIds.contains(calendarKey) ||
67+
!isBeforeFutureFeedStartDate(date)
68+
)
6369
) {
6470
String key = getTableScopedValue(keyValue);
6571
LOG.warn(

src/test/java/com/conveyal/datatools/manager/jobs/MergeFeedsJobTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ void canMergeRegionalWithOnlyCalendarFeed () throws SQLException {
231231
versions.add(onlyCalendarVersion);
232232
FeedVersion mergedVersion = regionallyMergeVersions(versions);
233233
SqlAssert sqlAssert = new SqlAssert(mergedVersion);
234+
sqlAssert.assertNoRefIntegrityErrors();
234235

235236
// - calendar table should have 2 records.
236237
sqlAssert.calendar.assertCount(2);
@@ -416,15 +417,15 @@ void mergeMTCShouldHandleMatchingTripIdsAndDropUnusedFutureCalendar() throws Exc
416417
sqlAssert.calendarDates.assertCount(5);
417418
// - only_calendar_id:
418419
// 1 from future feed (that service id is not scoped),
419-
sqlAssert.calendarDates.assertCount(1, "service_id = 'only_calendar_id'");
420+
sqlAssert.calendarDates.assertCount(1, "service_id='only_calendar_id'");
420421
// 0 from active feed
421422
// (in the active feed, that service id starts after the future feed start date)
422-
sqlAssert.calendarDates.assertCount(0, "service_id = 'Fake_Transit1:dropped_calendar_id'");
423+
sqlAssert.calendarDates.assertCount(0, "service_id='Fake_Transit1:dropped_calendar_id'");
423424
// - common_id:
424425
// 2 from active feed for the calendar item that was extended due to shared trip,
425-
sqlAssert.calendarDates.assertCount(2, "service_id = 'Fake_Transit7:common_id'");
426+
sqlAssert.calendarDates.assertCount(2, "service_id='Fake_Transit7:common_id'");
426427
// 2 from active feed for the active trip not in the future feed.
427-
sqlAssert.calendarDates.assertCount(2, "service_id = 'Fake_Transit1:common_id'");
428+
sqlAssert.calendarDates.assertCount(2, "service_id='Fake_Transit1:common_id'");
428429

429430
// The GTFS+ calendar_attributes table should contain the same number of entries as the calendar table
430431
// (reported by MTC).
@@ -505,6 +506,7 @@ void mergeMTCShouldHandleDisjointTripIds() throws SQLException {
505506
);
506507

507508
SqlAssert sqlAssert = new SqlAssert(mergeFeedsJob.mergedVersion);
509+
sqlAssert.assertNoRefIntegrityErrors();
508510

509511
// calendar table should have 4 records
510512
// - 2 records from future feed, including only_calendar_dates which absorbs its active counterpart,
@@ -613,6 +615,7 @@ void canMergeFeedsWithMTCForServiceIds1 () throws SQLException {
613615
mergeFeedsJob.run();
614616
assertFeedMergeSucceeded(mergeFeedsJob);
615617
SqlAssert sqlAssert = new SqlAssert(mergeFeedsJob.mergedVersion);
618+
sqlAssert.assertNoRefIntegrityErrors();
616619

617620
// - calendar table should have 4 records.
618621
sqlAssert.calendar.assertCount(4);
@@ -663,6 +666,7 @@ void canMergeFeedsWithMTCForServiceIds2 () throws SQLException {
663666
mergeFeedsJob.run();
664667
assertFeedMergeSucceeded(mergeFeedsJob);
665668
SqlAssert sqlAssert = new SqlAssert(mergeFeedsJob.mergedVersion);
669+
sqlAssert.assertNoRefIntegrityErrors();
666670

667671
// - calendar table should have 2 records.
668672
sqlAssert.calendar.assertCount(2);
@@ -710,6 +714,7 @@ void canMergeFeedsWithMTCForServiceIds3 () throws SQLException {
710714
mergeFeedsJob.run();
711715
assertFeedMergeSucceeded(mergeFeedsJob);
712716
SqlAssert sqlAssert = new SqlAssert(mergeFeedsJob.mergedVersion);
717+
sqlAssert.assertNoRefIntegrityErrors();
713718

714719
// - calendar table should have 3 records.
715720
sqlAssert.calendar.assertCount(3);
@@ -720,23 +725,23 @@ void canMergeFeedsWithMTCForServiceIds3 () throws SQLException {
720725
// within the future feed timespan.
721726
sqlAssert.calendarDates.assertCount(1, "service_id='common_id' and date='20170916'");
722727

723-
// - trips table should have 3 records.
724-
sqlAssert.trips.assertCount(3);
728+
// trips table should have 2 records.
729+
// - this includes all trips from both feed except the trip associated
730+
// with cal_to_remove, which calendar operates within the future feed.
731+
sqlAssert.trips.assertCount(2);
725732

726733
// common_id service_id should be scoped for earlier feed version.
727734
sqlAssert.trips.assertCount(1, "service_id='Fake_Agency4:common_id'");
728735

729-
// cal_to_remove service_id should be scoped for earlier feed version.
730-
sqlAssert.trips.assertCount(1, "service_id='Fake_Agency4:cal_to_remove'");
736+
// trips for cal_to_remove service_id should be removed.
737+
sqlAssert.trips.assertCount(0, "service_id='Fake_Agency4:cal_to_remove'");
731738

732739
// Amended calendar record from earlier feed version should also have a modified end date (one day before the
733740
// earliest start_date from the future feed).
734741
sqlAssert.calendar.assertCount(1, "service_id='Fake_Agency4:common_id' AND end_date='20170914'");
735742

736-
// Modified cal_to_remove should still exist in calendar_dates. It is modified even though it does not exist in
737-
// the future feed due to the MTC requirement to update all service_ids in the active feed.
738-
// See https://github.com/ibi-group/datatools-server/issues/244
739-
sqlAssert.calendarDates.assertCount(1, "service_id='Fake_Agency4:cal_to_remove'");
743+
// cal_to_remove should be removed from calendar_dates.
744+
sqlAssert.calendarDates.assertCount(0, "service_id='Fake_Agency4:cal_to_remove'");
740745
}
741746

742747
/**
@@ -754,6 +759,8 @@ void canMergeFeedsWithMTCForServiceIds4 () throws SQLException {
754759
mergeFeedsJob.run();
755760
assertFeedMergeSucceeded(mergeFeedsJob);
756761
SqlAssert sqlAssert = new SqlAssert(mergeFeedsJob.mergedVersion);
762+
// FIXME: "version3" contains ref integrity errors... was hat intentional?
763+
// sqlAssert.assertNoRefIntegrityErrors();
757764

758765
// - calendar table should have 3 records.
759766
sqlAssert.calendar.assertCount(3);

0 commit comments

Comments
 (0)