fix: finish KAN-278 terminology cleanup - #441
Conversation
|
Warning Review limit reached
Next review available in: 52 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change standardizes client-oriented terminology to company/person terminology across duplicate-phone reporting, CRM phone-call filtering, job events, search telemetry, schemas, frontend views, migrations, tests, and company-person data-quality analysis. ChangesCompany terminology alignment
Company-person data-quality analysis
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/workflow/tests/test_search_telemetry.py (1)
32-48: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAdd assertion for
event.source.The test sends
"source": "company_lookup"but never asserts the value was persisted. Addingassert event.source == "company_lookup"verifies the terminology change end-to-end through the API.💚 Proposed fix
assert event.result_count == 7 assert event.metadata == {"extra": "future-safe"} + assert event.source == "company_lookup"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/workflow/tests/test_search_telemetry.py` around lines 32 - 48, Add an assertion in the search telemetry test after retrieving the event to verify event.source equals "company_lookup", confirming the API persists the submitted source value end to end.
🧹 Nitpick comments (1)
scripts/analyze_company_people.py (1)
30-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer
Qobjects over queryset|operator.Using
Qobjects in a single.filter()call is the idiomatic Django pattern and avoids constructing two separate querysets.♻️ Proposed refactor
+from django.db.models import Count, Q + - empty_name_links = CompanyPersonLink.objects.filter( - person__name="" - ) | CompanyPersonLink.objects.filter(person__name__regex=r"^\s+$") + empty_name_links = CompanyPersonLink.objects.filter( + Q(person__name="") | Q(person__name__regex=r"^\s+$") + )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/analyze_company_people.py` around lines 30 - 32, Replace the queryset union assigned to empty_name_links with a single CompanyPersonLink.objects.filter() call combining the person__name="" and person__name__regex=r"^\s+$" conditions through a Q object, adding the required Django Q import.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/analyze_company_people.py`:
- Around line 135-138: Clarify the cleanup estimate logged in the final
logging.info call: rename “Total links after cleanup” to indicate it is an
estimate assuming all flagged links are removed, and calculate the deduction
using the union of empty-name and duplicate links so overlapping links are not
subtracted twice or produce negative values. Update the relevant counting logic
alongside empty_count and duplicate_count to track overlap or unique flagged
links.
---
Outside diff comments:
In `@apps/workflow/tests/test_search_telemetry.py`:
- Around line 32-48: Add an assertion in the search telemetry test after
retrieving the event to verify event.source equals "company_lookup", confirming
the API persists the submitted source value end to end.
---
Nitpick comments:
In `@scripts/analyze_company_people.py`:
- Around line 30-32: Replace the queryset union assigned to empty_name_links
with a single CompanyPersonLink.objects.filter() call combining the
person__name="" and person__name__regex=r"^\s+$" conditions through a Q object,
adding the required Django Q import.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 94e2da8c-e7c8-4d4c-acc6-ec6e6d7e1d12
⛔ Files ignored due to path filters (1)
frontend/src/api/generated/api.tsis excluded by!**/generated/**
📒 Files selected for processing (23)
apps/company/services/duplicate_phone_report.pyapps/company/tests/test_company_merge_service.pyapps/company/tests/test_duplicate_phone_report.pyapps/crm/tests/test_phone_call_service.pyapps/crm/views/phone_call_views.pyapps/job/migrations/0006_rename_job_event_people_company_terms.pyapps/job/models/job.pyapps/job/models/job_event.pyapps/job/serializers/data_quality_report_serializers.pyapps/job/services/kanban_service.pyapps/job/tests/test_duplicate_phones_view.pyapps/job/tests/test_job_event_terminology_migration.pyapps/workflow/migrations/0008_rename_search_telemetry_company_lookup_source.pyapps/workflow/tests/test_search_telemetry.pyapps/workflow/tests/test_search_telemetry_migration.pyfrontend/schema.ymlfrontend/src/components/CompanyLookup.vuefrontend/src/composables/useCompanyLookup.tsfrontend/src/pages/crm/__tests__/calls.pagination.test.tsfrontend/src/pages/crm/calls.vuefrontend/src/pages/reports/data-quality/duplicate-phones.vuescripts/analyze_client_contacts.pyscripts/analyze_company_people.py
💤 Files with no reviewable changes (1)
- scripts/analyze_client_contacts.py
There was a problem hiding this comment.
🧹 Nitpick comments (1)
scripts/analyze_company_people.py (1)
59-82: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDRY violation and N+1 query pattern in
flagged_link_ids().Two concerns:
The empty-name filter
Q(person__name="") | Q(person__name__regex=r"^\s+$")is duplicated betweenanalyze_empty_names(line 31–32) andflagged_link_ids(line 62–63). If the criteria change, both must be updated in sync. Extract to a module-level constant.The loop over
duplicate_groups(lines 73–79) issues a separate query per group — an N+1 pattern. For a small dataset this is negligible, but it can be avoided with a single batch query.♻️ Proposed refactor: extract shared filter and batch duplicate IDs
+EMPTY_NAME_FILTER = Q(person__name="") | Q(person__name__regex=r"^\s+$") + + def flagged_link_ids() -> set[UUID]: """Return company/person link IDs that need manual review.""" empty_name_ids = set( - CompanyPersonLink.objects.filter( - Q(person__name="") | Q(person__name__regex=r"^\s+$") - ).values_list("id", flat=True) + CompanyPersonLink.objects.filter(EMPTY_NAME_FILTER).values_list("id", flat=True) ) - duplicate_groups = ( - CompanyPersonLink.objects.values("company", "person__name") - .annotate(count=Count("id")) - .filter(count__gt=1) - ) - duplicate_ids: set[UUID] = set() - for duplicate in duplicate_groups: - duplicate_ids.update( - CompanyPersonLink.objects.filter( - company_id=duplicate["company"], - person__name=duplicate["person__name"], - ).values_list("id", flat=True) - ) + from collections import Counter + + all_links = list( + CompanyPersonLink.objects.values_list("id", "company_id", "person__name") + ) + group_counts = Counter((c, n) for _, c, n in all_links) + duplicate_keys = {k for k, v in group_counts.items() if v > 1} + duplicate_ids = {lid for lid, c, n in all_links if (c, n) in duplicate_keys} return empty_name_ids | duplicate_idsThen update
analyze_empty_namesto use the same constant:- empty_name_links = CompanyPersonLink.objects.filter( - Q(person__name="") | Q(person__name__regex=r"^\s+$") - ) + empty_name_links = CompanyPersonLink.objects.filter(EMPTY_NAME_FILTER)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/analyze_company_people.py` around lines 59 - 82, Refactor the shared empty-name predicate used by analyze_empty_names and flagged_link_ids into a module-level constant, then reuse it in both filters. In flagged_link_ids, replace the per-group CompanyPersonLink query loop with one batch query that identifies and returns all links matching the duplicate company/person-name combinations, preserving the existing empty-name and duplicate-ID union.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@scripts/analyze_company_people.py`:
- Around line 59-82: Refactor the shared empty-name predicate used by
analyze_empty_names and flagged_link_ids into a module-level constant, then
reuse it in both filters. In flagged_link_ids, replace the per-group
CompanyPersonLink query loop with one batch query that identifies and returns
all links matching the duplicate company/person-name combinations, preserving
the existing empty-name and duplicate-ID union.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2f5bdfc1-18e7-456d-9ed0-6dbdb46015f7
📒 Files selected for processing (2)
apps/workflow/tests/test_search_telemetry.pyscripts/analyze_company_people.py
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/workflow/tests/test_search_telemetry.py
Summary
Validation
Remaining KAN-278 Work
Summary by CodeRabbit
New Features
company_match, with clear rejection messaging for legacy filtering.cross_company).Bug Fixes