Skip to content

Fix top 3 Sentry production errors (~104K events)#3196

Draft
cursor[bot] wants to merge 2 commits intomainfrom
cursor/sentry-error-investigation-4382
Draft

Fix top 3 Sentry production errors (~104K events)#3196
cursor[bot] wants to merge 2 commits intomainfrom
cursor/sentry-error-investigation-4382

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented Mar 16, 2026

Addresses the three highest-impact unresolved production errors by event count:

1. RESEARCHHUB-BACKEND-4KPZ — AttributeError in OpenAlex license extraction (67,717 events)

  • Root cause: primary_location.get("source", {}) returns None (not {}) when the source key exists but its value is explicitly None. Calling .get("display_name") on None raises AttributeError.
  • Fix: Use isinstance(source, dict) check before accessing nested fields.

2. RESEARCHHUB-BACKEND-4KQ0 — Author.MultipleObjectsReturned (35,197 events)

  • Root cause: Author.objects.update_or_create(openalex_ids=...) calls .get() internally, which raises MultipleObjectsReturned when duplicate author records exist with the same openalex_ids.
  • Fix: Replace with filter().first() + manual update/create pattern to gracefully handle duplicates.

3. RESEARCHHUB-BACKEND-4KKS — BulkIndexError in OpenSearch user indexing (1,130 events)

  • Root cause: UserDocument.author_profile is defined as ObjectField() without explicit property types. OpenSearch uses dynamic mapping, which can infer headline as an object type from one document and then reject string values from subsequent documents.
  • Fix: Add explicit properties (id, headline, profile_image) to the ObjectField definition.

Tests added:

  • 6 unit tests for _extract_license_info edge cases (null source, missing source, valid source, empty/null primary_location, non-dict source)
  • 3 integration tests for process_authors (duplicate handling, creation, update)
Open in Web View Automation 

cursoragent and others added 2 commits March 16, 2026 21:33
…pleObjectsReturned, OpenSearch headline mapping

Fixes RESEARCHHUB-BACKEND-4KPZ: _extract_license_info crashes when
OpenAlex 'source' field is explicitly null (67K events). The dict.get()
default only applies when the key is missing, not when the value is None.
Use isinstance check instead.

Fixes RESEARCHHUB-BACKEND-4KQ0: Author.objects.update_or_create raises
MultipleObjectsReturned when duplicate openalex_ids exist (35K events).
Replace with filter().first() + manual update/create pattern.

Fixes RESEARCHHUB-BACKEND-4KKS: UserDocument author_profile ObjectField
lacks explicit property definitions, causing OpenSearch to infer headline
as an object type from dynamic mapping. Add explicit properties to
prevent mapper_parsing_exception (1.1K events).

Co-authored-by: Kobe Attias <kobeattias@gmail.com>
…ndling

Tests for RESEARCHHUB-BACKEND-4KPZ: Verify _extract_license_info handles
null source, missing source, valid source, empty/null primary_location,
and non-dict source values.

Tests for RESEARCHHUB-BACKEND-4KQ0: Verify process_authors handles
duplicate openalex_ids, creates new authors, and updates existing ones.

Co-authored-by: Kobe Attias <kobeattias@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.59%. Comparing base (496a262) to head (3e2a6fb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3196      +/-   ##
==========================================
+ Coverage   78.49%   78.59%   +0.10%     
==========================================
  Files         612      612              
  Lines       34250    34255       +5     
==========================================
+ Hits        26885    26924      +39     
+ Misses       7365     7331      -34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant