-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
_update_video_aggregate_rating() in app/services/rating_service.py (lines 31-71) tries to $set three camelCase columns on the videos table that don't exist in the Cassandra schema:
averageRatingtotalRatingsCountupdatedAt
This produces an UNKNOWN_TABLE_COLUMNS error on every rating submission:
WARNING:astrapy.utils.api_commander:APICommander about to raise from:
[{'errorCode': 'UNKNOWN_TABLE_COLUMNS', 'message': 'The table killrvideo.videos defines the columns:
videoid, added_date, ... views, youtube_id. The update included the following unknown columns:
"averageRating", "totalRatingsCount", "updatedAt".'}]
The error is silently caught (lines 64-71), so ratings return 200 — but aggregated values are never persisted, and get_video_ratings_summary() always returns averageRating=None, totalRatingsCount=0.
Root Cause
The schema has a dedicated counter table for this purpose that isn't being used:
CREATE TABLE IF NOT EXISTS killrvideo.video_ratings (
videoid uuid PRIMARY KEY,
rating_counter counter,
rating_total counter
);Required Changes
Write path (_update_video_aggregate_rating)
Replace the $set on videos with counter operations on video_ratings:
- On new rating: increment
rating_counterby 1, incrementrating_totalby the rating value - On updated rating: increment
rating_totalby(new_rating - old_rating)(counter stays the same) - Note: Counters use
$inc, not$set
Read path (get_video_ratings_summary)
Instead of reading averageRating/totalRatingsCount from the Video model (which are always None/0):
- Query the
video_ratingstable for the video'srating_counterandrating_total - Compute
average = rating_total / rating_counteron the fly - Return the computed values
Files to modify
app/services/rating_service.py— rewrite_update_video_aggregate_rating()andget_video_ratings_summary()app/models/video.py— consider removingaverageRating,totalRatingsCount,updatedAtfields (or keeping them as API-only computed fields)tests/services/test_rating_service.py— update tests for the new approach
Acceptance criteria
- Rating submission uses
video_ratingscounter table (notvideos) -
GET /videos/{id}/ratingsreturns correctaverageRatingandtotalRatingsCount - No more
UNKNOWN_TABLE_COLUMNSwarnings in logs - Existing tests pass, new tests cover counter logic
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working