From d8e6931b85361ac5d791fc3408bb375ea920d3f4 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 30 Jan 2026 22:50:07 -0500 Subject: [PATCH] fix: ensure Companies and Resources get filters during incremental sync fallback Fixed critical logic bug where Companies and Resources were not getting proper filters applied when falling back from incremental to full sync. Root Cause: - During scheduled incremental sync, Companies and Resources correctly identify they don't support incremental sync - However, the filter-building logic was in an else block that only executed for non-incremental syncs - This caused Companies and Resources to sync with NO filters at all - Autotask API now rejects queries without filters, returning: 'Value cannot be null. Parameter name: filters' Fix: - Restructured logic so filter building happens for BOTH: 1. Non-incremental (full) syncs 2. Incremental syncs that fall back to full sync - Companies and Resources now get active filters applied even during scheduled incremental syncs This resolves the scheduled sync failures for Companies, Resources, and all other entities that were failing due to the cascading effect of early failures. --- lib/services/entity-sync.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/services/entity-sync.ts b/lib/services/entity-sync.ts index 13c371e..c847b6b 100644 --- a/lib/services/entity-sync.ts +++ b/lib/services/entity-sync.ts @@ -102,10 +102,14 @@ export class EntitySyncService { entityLogger.error('Failed to get last sync time', {}, err); throw new Error(`Failed to determine sync time: ${err.message}`); } - } else if (isIncremental && !supportsIncremental) { - entityLogger.info(`${entity} does not support incremental sync, performing full sync instead`); - } else { - // For full sync, build filters + } + + // For full sync OR entities that don't support incremental, build filters + if (!isIncremental || (isIncremental && !supportsIncremental)) { + if (isIncremental && !supportsIncremental) { + entityLogger.info(`${entity} does not support incremental sync, performing full sync instead`); + } + const filters: Array<{ field: string; op: string; value: any }> = []; // Special handling for entities that require filters