-
Notifications
You must be signed in to change notification settings - Fork 2
Improve queries with in bulk #3477
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: main
Are you sure you want to change the base?
Changes from all commits
bb0683d
e629003
304aefb
1a38dd6
54eb754
fb61b7c
547894c
6f9ec41
707d193
b53edde
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 |
|---|---|---|
|
|
@@ -500,8 +500,11 @@ def batch_upsert_associations_chunked(order_ids: List[int]): # noqa: UP006 | |
| line_associations_batch = [] | ||
| hubspot_client = HubspotApi() | ||
| deal_count = len(order_ids) | ||
| deals_by_id = Order.objects.in_bulk(order_ids) | ||
| for idx, order_id in enumerate(order_ids): | ||
| deal = Order.objects.get(id=order_id) | ||
| deal = deals_by_id.get(order_id) | ||
| if not deal: | ||
| continue | ||
|
Comment on lines
+505
to
+507
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. Bug: If the last order in a batch is missing from the database, accumulated association data is silently dropped and never sent to HubSpot due to a skipped final flush. Suggested FixDecouple the final flush logic from the item processing loop. After the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| contact_id = get_hubspot_id_for_object(deal.purchaser) | ||
| deal_id = get_hubspot_id_for_object(deal) | ||
| for line in deal.lines.iterator(): | ||
|
|
||
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.
Bug: The code calls
.dataon the result ofsuper().to_representation(instance), which can beNoneif an order has no transactions, causing anAttributeError.Severity: HIGH
Suggested Fix
Before accessing the
.dataattribute on thetransactionobject, add a check to ensure it is notNone. This handles cases where an order may not have any associated transactions.Prompt for AI Agent