Skip to content

Commit ca8f67d

Browse files
committed
fix remove use_trs field
1 parent 68a0ba7 commit ca8f67d

File tree

2 files changed

+25
-68
lines changed

2 files changed

+25
-68
lines changed

server/stt/io/feeding_services/stt_tt_content_api.py

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,6 @@ def _headers(self, api_key: str) -> Dict[str, str]:
7474
"paginating. Range: 1-10000."
7575
),
7676
},
77-
{
78-
"id": "use_trs",
79-
"type": "boolean",
80-
"label": "Use incremental sync (trs)",
81-
"required": True,
82-
"default": True,
83-
"description": (
84-
"When enabled, add the 'trs' query param with the last-updated timestamp "
85-
"to fetch only items changed since the previous run."
86-
),
87-
},
8877
{
8978
"id": "since_minutes",
9079
"type": "text",
@@ -166,7 +155,6 @@ def _fetch_tt_data(self, provider, update) -> List[Dict]:
166155
- page_size: int (default 50)
167156
- max_pages: int safety cap (default 200)
168157
- timeout: int per-request timeout (default 60)
169-
- use_trs: bool (default True, 'trs' is RFC3339 timestamp in UTC)
170158
- since_minutes: int fallback lookback (default 1440)
171159
"""
172160
url, api_key = self._get_config(provider)
@@ -178,36 +166,26 @@ def _fetch_tt_data(self, provider, update) -> List[Dict]:
178166
# safety cap to avoid runaway loops
179167
timeout = int(config.get("timeout", 60))
180168

181-
use_trs_config = config.get("use_trs", True)
182-
if isinstance(use_trs_config, str):
183-
use_trs = use_trs_config.strip().lower() in {"true", "1", "yes", "on"}
184-
else:
185-
use_trs = bool(use_trs_config)
186169
trs_value: str | None = None
187-
if use_trs:
188-
# Prefer last_updated from the update context, fallback to provider storage or lookback window
189-
last_updated_str = None
190-
if isinstance(update, dict):
191-
last_updated_str = update.get("last_updated") or update.get(
192-
"last_update"
193-
)
194-
# Parse if available
195-
dt_from: datetime | None = None
196-
if isinstance(last_updated_str, str):
197-
try:
198-
# Accept ISO-8601 with/without Z
199-
dt_from = datetime.fromisoformat(
200-
last_updated_str.replace("Z", "+00:00")
201-
)
202-
except Exception:
203-
dt_from = None
204-
if dt_from is None:
205-
# Fallback: now - since_minutes
206-
minutes = int(config.get("since_minutes", 1440))
207-
dt_from = datetime.now(timezone.utc) - timedelta(minutes=minutes)
208-
# TT expects 'trs' as an RFC3339 timestamp in UTC with seconds precision
209-
dt_from = dt_from.astimezone(timezone.utc).replace(microsecond=0)
210-
trs_value = dt_from.strftime("%Y-%m-%dT%H:%M:%SZ")
170+
# Prefer last_updated from the update context, fallback to provider storage or lookback window
171+
last_updated_str = None
172+
if isinstance(update, dict):
173+
last_updated_str = update.get("last_updated") or update.get("last_update")
174+
# Parse if available
175+
dt_from: datetime | None = None
176+
if isinstance(last_updated_str, str):
177+
try:
178+
# Accept ISO-8601 with/without Z
179+
dt_from = datetime.fromisoformat(last_updated_str.replace("Z", "+00:00"))
180+
except Exception:
181+
dt_from = None
182+
if dt_from is None:
183+
# Fallback: now - since_minutes
184+
minutes = int(config.get("since_minutes", 1440))
185+
dt_from = datetime.now(timezone.utc) - timedelta(minutes=minutes)
186+
# TT expects 'trs' as an RFC3339 timestamp in UTC with seconds precision
187+
dt_from = dt_from.astimezone(timezone.utc).replace(microsecond=0)
188+
trs_value = dt_from.strftime("%Y-%m-%dT%H:%M:%SZ")
211189

212190
# Prepare base URL components and preserve existing query params
213191
parsed = urlparse(url)

server/tests/stt_tt_content_api_test.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ def test_fetch_data_different_response_formats(self, mock_get):
377377
self.assertEqual(test_items[0]["uri"], items[0]["uri"])
378378

379379
@patch.object(STTTTContentAPIService, "_get_with_retry")
380-
def test_fetch_data_uses_trs_with_last_updated(self, mock_get):
381-
"""When use_trs is enabled and update contains last_updated, include trs in query."""
380+
def test_fetch_data_adds_trs_with_last_updated(self, mock_get):
381+
"""When update contains last_updated, include trs in query."""
382382
# minimal 1-page flow
383383
mock_get.side_effect = [
384384
MockResponse({"hits": [TEST_TT_ITEMS[0]]}),
@@ -389,7 +389,6 @@ def test_fetch_data_uses_trs_with_last_updated(self, mock_get):
389389
"config": {
390390
"url": "https://api.example.com/contentapi/items",
391391
"api_key": "MY_TOKEN",
392-
"use_trs": True,
393392
}
394393
}
395394
update = {"last_updated": "2025-09-24T10:00:00Z"}
@@ -403,7 +402,7 @@ def test_fetch_data_uses_trs_with_last_updated(self, mock_get):
403402

404403
@patch.object(STTTTContentAPIService, "_get_with_retry")
405404
def test_fetch_data_uses_trs_fallback_since_minutes(self, mock_get):
406-
"""When use_trs enabled but no last_updated, use now - since_minutes as trs."""
405+
"""When no last_updated, use now - since_minutes as trs."""
407406
# one page then empty
408407
mock_get.side_effect = [
409408
MockResponse({"hits": [TEST_TT_ITEMS[0]]}),
@@ -414,7 +413,6 @@ def test_fetch_data_uses_trs_fallback_since_minutes(self, mock_get):
414413
"config": {
415414
"url": "https://api.example.com/contentapi/items",
416415
"api_key": "MY_TOKEN",
417-
"use_trs": True,
418416
"since_minutes": "120",
419417
}
420418
}
@@ -455,27 +453,8 @@ def test_timeout_configurable(self, mock_get):
455453
self.assertEqual(15, call_args[1]["timeout"])
456454

457455
@patch.object(STTTTContentAPIService, "_get_with_retry")
458-
def test_use_trs_boolean_coercion_from_text(self, mock_get):
459-
"""use_trs text values like 'true' should be treated as boolean True."""
460-
mock_get.side_effect = [MockResponse({"hits": []})]
461-
provider = {
462-
"config": {
463-
"url": "https://api.example.com/contentapi/items",
464-
"api_key": "MY_TOKEN",
465-
"use_trs": "true",
466-
}
467-
}
468-
update = {"last_updated": "2025-09-24T10:00:00Z"}
469-
470-
_ = self.service._fetch_tt_data(provider, update)
471-
472-
call_args = mock_get.call_args
473-
url = call_args[0][0]
474-
self.assertIn("trs=2025-09-24T10%3A00%3A00Z", url)
475-
476-
@patch.object(STTTTContentAPIService, "_get_with_retry")
477-
def test_use_trs_disabled_no_param(self, mock_get):
478-
"""When use_trs is disabled, the trs param should not be present."""
456+
def test_trs_enforced_even_when_legacy_config_disables(self, mock_get):
457+
"""Legacy configs with use_trs=False should still yield trs in query."""
479458
mock_get.side_effect = [MockResponse({"hits": []})]
480459
provider = {
481460
"config": {
@@ -490,7 +469,7 @@ def test_use_trs_disabled_no_param(self, mock_get):
490469

491470
call_args = mock_get.call_args
492471
url = call_args[0][0]
493-
self.assertNotIn("trs=", url)
472+
self.assertIn("trs=2025-09-24T10%3A00%3A00Z", url)
494473

495474
@patch.object(STTTTContentAPIService, "_get_with_retry")
496475
def test_fetch_data_list_response(self, mock_get):

0 commit comments

Comments
 (0)