[FIX] Use correct primary key in prompt studio list count subquery#1902
[FIX] Use correct primary key in prompt studio list count subquery#1902chandrasekharan-zipstack wants to merge 1 commit intomainfrom
Conversation
ToolStudioPrompt uses prompt_id as its primary key, not id.
Count("id") causes FieldError on the list endpoint (500).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughA queryset annotation in the views module was updated to count rows by Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Test ResultsSummary
Runner Tests - Full Report
SDK1 Tests - Full Report
|
|
| Filename | Overview |
|---|---|
| backend/prompt_studio/prompt_studio_core_v2/views.py | Correct fix: Count("prompt_id") now matches ToolStudioPrompt's actual UUID primary key, resolving the 500 on the list endpoint. |
Sequence Diagram
sequenceDiagram
participant Client
participant PromptStudioCoreView
participant Django ORM
participant DB as PostgreSQL
Client->>PromptStudioCoreView: GET /api/v1/unstract/{org_id}/prompt-studio/
PromptStudioCoreView->>Django ORM: get_queryset() — action=="list"
Django ORM->>Django ORM: Build subquery: ToolStudioPrompt\n.filter(tool_id=OuterRef("pk"))\n.values("tool_id")\n.annotate(cnt=Count("prompt_id"))\n.values("cnt")
Django ORM->>Django ORM: Annotate CustomTool qs with _prompt_count=Subquery(...)
Django ORM->>DB: SELECT ... (subquery counts by prompt_id)
DB-->>Django ORM: Rows with _prompt_count
Django ORM-->>PromptStudioCoreView: QuerySet[CustomTool]
PromptStudioCoreView-->>Client: 200 OK — serialized list
Reviews (1): Last reviewed commit: "[FIX] Use correct primary key field in p..." | Re-trigger Greptile



What
FieldError: Cannot resolve keyword 'id' into fieldon the prompt studio list endpoint by using the correct primary key field name.Why
ToolStudioPromptusesprompt_id(UUID) as its primary key, notid. TheCount("id")in the prompt count subquery introduced in #1901 causes a 500 onGET /api/v1/unstract/{org_id}/prompt-studio/.How
Count("id")→Count("prompt_id")in the subquery annotation inPromptStudioCoreView.get_queryset().Can this PR break any existing features
No. Single field reference fix in a subquery annotation.
Database Migrations
Env Config
Relevant Docs
Related Issues or PRs
Dependencies Versions
Notes on Testing
Verified the list endpoint no longer returns 500 after the fix.
Screenshots