Skip to content

Commit 835b9e2

Browse files
pmcfadinclaude
andcommitted
fix: gracefully handle view tracking limitation in Table API
The Astra DB Table API does not yet expose the 'views' column defined in the CQL schema, causing UNKNOWN_TABLE_COLUMNS errors. Additionally, the Table API does not support the $inc operation, resulting in UNSUPPORTED_UPDATE_OPERATIONS errors. This commit implements graceful degradation by: - Catching both error codes specifically - Logging a clear warning message once per process - Returning success without updating views (no-op) - Preserving activity table logging for analytics - Preventing 500 errors on the /view endpoint The fix is future-proof: when API support is added, the code will automatically resume normal operation. Refs: docs/schema-astra.cql:95 (views column definition) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 88d7cbb commit 835b9e2

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

app/services/video_service.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@
8888
logging.getLogger().getEffectiveLevel(),
8989
)
9090

91+
# Flag to track if we've logged the view tracking limitation warning
92+
_logged_views_disabled = False
93+
9194

9295
# ---------------------------------------------------------------------------
9396
# Helpers
@@ -384,6 +387,10 @@ async def record_video_view(
384387
) -> None:
385388
"""Increment the view counter stored directly in the *videos* table.
386389
390+
NOTE: View tracking is currently disabled. The 'views' column exists in the
391+
CQL schema but is not yet exposed via the Astra DB Table API. This function
392+
will gracefully no-op until API support is added.
393+
387394
The dedicated ``video_playback_stats`` counter table is no longer updated –
388395
we instead mutate the new ``views`` bigint column in the primary table so
389396
the entire workflow remains Data-API-only.
@@ -400,11 +407,33 @@ async def record_video_view(
400407
upsert=True,
401408
)
402409
except DataAPIResponseException as exc:
410+
global _logged_views_disabled
411+
error_str = str(exc)
412+
413+
# Check if this is the known Table API limitation where the 'views' column
414+
# exists in CQL schema but isn't exposed via the Table API yet
415+
if (
416+
"UNKNOWN_TABLE_COLUMNS" in error_str
417+
or "UNSUPPORTED_UPDATE_OPERATIONS" in error_str
418+
):
419+
# Log warning once per process lifecycle to avoid log spam
420+
if not _logged_views_disabled:
421+
logger.warning(
422+
"View tracking is currently disabled. The 'views' column exists in "
423+
"the CQL schema (docs/schema-astra.cql:95) but is not yet exposed "
424+
"via the Astra DB Table API. Views will not be tracked until API "
425+
"support is added. Error codes: UNKNOWN_TABLE_COLUMNS / "
426+
"UNSUPPORTED_UPDATE_OPERATIONS_FOR_TABLE"
427+
)
428+
_logged_views_disabled = True
429+
return # Gracefully no-op without breaking the API contract
430+
403431
# Some deployments (Astra *tables*) currently reject $inc on bigint –
404432
# fall back to a manual read-modify-write cycle.
405-
if "Update operation not supported" in str(
406-
exc
407-
) or "unsupported operations" in str(exc):
433+
if (
434+
"Update operation not supported" in error_str
435+
or "unsupported operations" in error_str
436+
):
408437
current = (
409438
await db_table.find_one(
410439
filter={"videoid": _uuid_for_db(video_id, db_table)}

0 commit comments

Comments
 (0)