Skip to content

fix(auth): ensure current_user is never None in BaseInteractor - #2157

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/base-interactor-current-user-none
Open

fix(auth): ensure current_user is never None in BaseInteractor#2157
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/base-interactor-current-user-none

Conversation

@sentry

@sentry sentry Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an AttributeError: 'NoneType' object has no attribute 'is_authenticated' that occurred when TriggerSyncInteractor.validate() was called during staff impersonation.

Root Cause:
In BaseInteractor.__init__, when self.current_owner was present, self.current_user was directly assigned self.current_owner.user. If the impersonated owner did not have a linked Django User object, self.current_owner.user would be None, leading to self.current_user also being None. Subsequent calls to self.current_user.is_authenticated would then raise the AttributeError.

Fix:
Modified BaseInteractor.__init__ to ensure that self.current_user always defaults to Django's AnonymousUser() if self.current_owner.user is None. This aligns with Django's standard practice and guarantees that self.current_user is always an object with an is_authenticated attribute, preventing NoneType errors in interactors.

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes API-EZD

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@thomasrockhu-codecov

thomasrockhu-codecov commented Aug 28, 2026

Copy link
Copy Markdown
Contributor
✨ Harness AI Code Review View in Harness →

Risk: LOW

This PR fixes an AttributeError: 'NoneType' object has no attribute 'is_authenticated' in BaseInteractor.__init__ by defaulting self.current_user to AnonymousUser() when an impersonated owner has no linked Django User. The change is a single defensive null-guard that mirrors the existing current_user or AnonymousUser() pattern already used a few lines above, and the description accurately matches the diff.

No issues found above the confidence threshold.

@codecov-notifications

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.63%. Comparing base (17e0f08) to head (1919b54).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2157   +/-   ##
=======================================
  Coverage   91.63%   91.63%           
=======================================
  Files        1337     1337           
  Lines       53262    53262           
  Branches     1647     1647           
=======================================
  Hits        48805    48805           
  Misses       4136     4136           
  Partials      321      321           
Flag Coverage Δ
apiunit 93.98% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

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