-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(llma): wire up auto-create hook, generated types, and MCP tools #54367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: andy/llma-eval-reports-4-frontend
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,6 +235,16 @@ def _get_config_length(instance) -> int: | |
| def perform_create(self, serializer): | ||
| instance = serializer.save() | ||
|
|
||
| # Auto-create a default report config so reports are generated from the start. | ||
| # Users can later add email/Slack delivery targets if they want notifications. | ||
| from products.llm_analytics.backend.models.evaluation_reports import EvaluationReport | ||
|
|
||
| EvaluationReport.objects.create( | ||
| team=self.team, | ||
| evaluation=instance, | ||
| start_date=instance.created_at, | ||
| ) | ||
|
Comment on lines
235
to
+246
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Wrap both operations in from django.db import transaction
def perform_create(self, serializer):
with transaction.atomic():
instance = serializer.save()
from ..models.evaluation_reports import EvaluationReport
EvaluationReport.objects.create(
team=self.team,
evaluation=instance,
start_date=instance.created_at,
)
# tracking/analytics below can remain outside the transactionPrompt To Fix With AIThis is a comment left during a code review.
Path: products/llm_analytics/backend/api/evaluations.py
Line: 235-246
Comment:
**Auto-create and evaluation save are not in the same transaction**
`serializer.save()` commits the evaluation in its own implicit transaction. If `EvaluationReport.objects.create()` then raises (e.g. a DB error or constraint violation), the user receives a 500 but the evaluation row is already persisted. They will likely retry, creating a duplicate evaluation, while the original silently exists without any report.
Wrap both operations in `transaction.atomic()` so a failed report creation rolls back the evaluation too:
```python
from django.db import transaction
def perform_create(self, serializer):
with transaction.atomic():
instance = serializer.save()
from ..models.evaluation_reports import EvaluationReport
EvaluationReport.objects.create(
team=self.team,
evaluation=instance,
start_date=instance.created_at,
)
# tracking/analytics below can remain outside the transaction
```
How can I resolve this? If you propose a fix, please make it concise.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valid point. Wrapping both in |
||
|
|
||
| # Calculate properties for tracking | ||
| conditions = instance.conditions or [] | ||
| condition_count = len(conditions) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no circular-import risk here —
evaluation_reports.pyonly imports fromposthog.models.utilsand standard library modules. Move this to the top of the file alongside the other..models.*imports, using the same relative-import style:Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, no circular import risk here. Will move to module-level alongside the other
..models.*imports.