tanishqgandhi1908 opened a new pull request, #9226:
URL: https://github.com/apache/texera/pull/9226

   ### What changes were proposed in this PR?
   
   A logged-out viewer's page sends `POST /api/hub/view` with `userId: 0`. 
`postView` incremented the view count, then inserted a `user_action` row with 
`uid = 0`. That breaks the foreign key to `user(uid)`, since no user has uid 0, 
so the request returned 500 and the view was never recorded, though the count 
had already gone up.
   
   - `postView` now records the view with a `NULL` uid when `userId` is `0` or 
missing. `user_action.uid` is nullable, and migration `13.sql` already stored 
the old anonymous views as `NULL`.
   - `recordUserAction`'s default `userId` is now `null` instead of `0`, so the 
default can't hit the same foreign key. No caller relies on it.
   
   Before and after, sending the logged-out request 
(`{"entityId":8,"userId":0,"entityType":"workflow"}`) three times:
   
   | | Responses | view_count (from 42) | user_action view rows |
   |---|---|---|---|
   | Before | 500, 500, 500 | 45 | 0 |
   | After | 200, 200, 200 | 45 | 3, uid NULL |
   
   ### Any related issues, documentation, discussions?
   
   Closes #9225.
   
   ### How was this PR tested?
   
   New `HubResourceSpec` test: a view with `userId: 0` and one with no `userId` 
both return the next count and are recorded with a `NULL` uid. It fails without 
the fix. `HubResourceSpec` passes (73/73), and `scalafmtCheckAll` and 
`scalafixAll --check` are clean. The before/after table above came from running 
the requests against a local server.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Opus 5.5)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to