tanishqgandhi1908 opened a new issue, #9225:
URL: https://github.com/apache/texera/issues/9225

   ### What happened?
   
   When a logged-out user opens a public workflow, dataset or model, the 
frontend calls `POST /api/hub/view` with `userId: 0` (`workspace.component.ts`, 
`dataset-detail.component.ts`, `model-detail.component.ts`). 
`HubResource.postView` first increments the view count, then inserts a 
`user_action` row with `uid = 0`. No user has uid 0, so the insert violates 
`user_action`'s foreign key to `user(uid)` and the request returns 500. The 
view count has already been incremented, so the count still goes up, but no 
view is recorded in `user_action`.
   
   `user_action.uid` is nullable. Migration `sql/updates/13.sql` already 
converted the old anonymous `uid = 0` rows to `NULL` when it added the foreign 
key, but the code still sends 0.
   
   Expected: an anonymous view returns 200 and is recorded with a `NULL` uid.
   
   ### How to reproduce?
   
   1. Pick a public workflow, e.g. wid 8.
   2. Send the request the frontend sends for a logged-out viewer:
      `curl -X POST localhost:8080/api/hub/view -H 'Content-Type: 
application/json' -d '{"entityId":8,"userId":0,"entityType":"workflow"}'`
   3. It returns 500. `workflow_view_count.view_count` for wid 8 goes up by 1, 
but no `user_action` row is added.
   4. The same request with a real `userId` returns 200 and adds the row.
   
   | Request | Response | view_count | user_action rows |
   |---|---|---|---|
   | Before | — | 42 | 0 |
   | 3 × `userId: 0` | 500 | 45 | 0 |
   | 1 × `userId: 1` | 200 | 46 | 1 |
   
   
   ### Version/Branch
   
   1.4.0-incubating-SNAPSHOT (main)
   
   ### Commit Hash (Optional)
   
   _No response_
   
   ### What browsers are you seeing the problem on?
   
   _No response_
   
   ### Relevant log output
   
   ```shell
   
   ```


-- 
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