Skip to content

Conversation

@EmmaLouise2018
Copy link
Contributor

@EmmaLouise2018 EmmaLouise2018 commented Oct 24, 2025

The SyncJob model uses 'progress' field (not 'progress_data') to store
sync progress information. Updated all references in background_sync_service.py:

- Line 97: SyncJob creation now uses progress={...} instead of progress=0 + progress_data={...}
- Line 67: Stale sync check now uses existing_sync.progress
- Line 379: Progress update now uses sync_job.progress

This fixes the 'progress_data is an invalid keyword argument' error
when syncing inventory from GAM.
The SyncJob model requires adapter_type as a non-null field, but the
start_inventory_sync_background function wasn't providing it when
creating the sync job record.

Changes:
- Query AdapterConfig to get tenant's adapter_type before creating SyncJob
- Add adapter_type field to SyncJob() constructor
- Defaults to 'mock' if no adapter config found (graceful fallback)

This fixes the database constraint violation:
'null value in column adapter_type violates not-null constraint'

Resolves GAM inventory sync failures.
The SyncJob.summary field is defined as Text (string), not JSONType,
but the code was trying to assign a dict directly, causing issues.

Also removed the duration_seconds calculation that was causing:
'can't subtract offset-naive and offset-aware datetimes'

Changes:
- Convert summary dict to JSON string before storing
- Removed duration_seconds field assignment (field doesn't exist in model)
- This fixes the backend error when marking sync complete

The frontend error 'Cannot read properties of undefined (reading total)'
is likely because summary wasn't being stored properly.
- Admin UI was trying to fetch products from this endpoint but it didn't exist
- This endpoint returns basic product data (product_id, name, description, delivery_type)
- Used by admin UI for product listing/selection
Two major issues fixed:

1. Settings page sync buttons (404 error):
   - Changed URL from /tenant/{id}/gam/sync-inventory to /api/tenant/{id}/inventory/sync
   - Updated response handling for new format: {sync_id, status, message}
   - Fixed 'Cannot read properties of undefined' error using optional chaining (?)

2. Inventory browser sync (cannot read 'total' error):
   - Fixed sync to properly handle async background jobs
   - Added polling for sync completion status
   - Use optional chaining to safely access summary.ad_units?.total
   - Now shows progress and reloads page when complete

Both pages now correctly use the /api/tenant/{id}/inventory/sync endpoint
and handle the 202 Accepted response with background job polling.
@EmmaLouise2018 EmmaLouise2018 self-assigned this Oct 25, 2025
@EmmaLouise2018 EmmaLouise2018 marked this pull request as ready for review October 25, 2025 00:43
@EmmaLouise2018 EmmaLouise2018 merged commit d300258 into main Oct 25, 2025
8 checks passed
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
…dmin-inventory-sync-only

fix: inventory sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants