Skip to content

Fix ObjectDoesNotExist using invalid keyword argument#3534

Merged
arkid15r merged 2 commits intoOWASP:mainfrom
preeeetham:fix/object-does-not-exist-keyword-arg
Jan 25, 2026
Merged

Fix ObjectDoesNotExist using invalid keyword argument#3534
arkid15r merged 2 commits intoOWASP:mainfrom
preeeetham:fix/object-does-not-exist-keyword-arg

Conversation

@preeeetham
Copy link
Contributor

Proposed change

Resolves #3521

This PR fixes ObjectDoesNotExist(msg=...) which causes TypeError instead of the intended exception. Django's ObjectDoesNotExist does not accept keyword arguments:

>>> from django.core.exceptions import ObjectDoesNotExist
>>> raise ObjectDoesNotExist(msg='test')
TypeError: ObjectDoesNotExist() takes no keyword arguments

This means error handling was completely broken for these code paths - users would see TypeError instead of proper "not found" messages.

Changes

  • Replace all 11 instances of ObjectDoesNotExist(msg=...) with positional arguments
  • Add ASSIGNEE_NOT_FOUND_MSG constant to follow linter rules (EM101, TRY003)
  • Use variable for f-string message to satisfy EM102 rule
Before (broken) After (fixed)
ObjectDoesNotExist(msg=MODULE_NOT_FOUND_MSG) ObjectDoesNotExist(MODULE_NOT_FOUND_MSG)
ObjectDoesNotExist(msg="Assignee not found.") ObjectDoesNotExist(ASSIGNEE_NOT_FOUND_MSG)
ObjectDoesNotExist(msg=ISSUE_NOT_FOUND_MSG) ObjectDoesNotExist(ISSUE_NOT_FOUND_MSG)

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

Django's ObjectDoesNotExist exception does not accept keyword
arguments. Using `ObjectDoesNotExist(msg=...)` raises a TypeError
instead of the intended ObjectDoesNotExist exception, breaking
error handling in the mentorship module mutations.

Changes:
- Replace `ObjectDoesNotExist(msg=...)` with positional arguments
- Add ASSIGNEE_NOT_FOUND_MSG constant to follow linter rules
- Use variable for f-string message to satisfy EM102 rule

Fixes OWASP#3521
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

Summary by CodeRabbit

  • Refactor

    • Improved consistency in error message handling within the mentorship backend.
  • Chores

    • Internal code standardization and maintenance.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This PR fixes broken error handling in the mentorship module mutations by correcting ObjectDoesNotExist exception instantiation. It introduces centralized message constants for not-found scenarios and replaces invalid keyword argument usage with positional arguments, ensuring proper exception raising and GraphQL error handling.

Changes

Cohort / File(s) Summary
Error Handling and Message Constants
backend/apps/mentorship/api/internal/mutations/module.py
Introduced ASSIGNEE_NOT_FOUND_MSG, ISSUE_NOT_FOUND_MSG, and MODULE_NOT_FOUND_MSG constants. Replaced 11 instances of ObjectDoesNotExist(msg=...) with positional argument syntax ObjectDoesNotExist(...). Replaced hard-coded error strings with the new constants throughout the module.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

backend

Suggested reviewers

  • arkid15r
  • kasya
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing ObjectDoesNotExist calls that incorrectly use a keyword argument instead of positional arguments.
Description check ✅ Passed The description is directly related to the changeset, explaining the bug, the fix applied, and the specific changes made to resolve issue #3521.
Linked Issues check ✅ Passed The PR fully addresses issue #3521 by fixing all 11 instances of ObjectDoesNotExist with keyword arguments, adding the ASSIGNEE_NOT_FOUND_MSG constant, and ensuring linter compliance.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the ObjectDoesNotExist keyword argument issue in module.py; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arkid15r arkid15r enabled auto-merge January 25, 2026 04:13
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.48%. Comparing base (0299256) to head (3df1348).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3534   +/-   ##
=======================================
  Coverage   85.48%   85.48%           
=======================================
  Files         461      461           
  Lines       14240    14240           
  Branches     1896     1896           
=======================================
  Hits        12173    12173           
  Misses       1688     1688           
  Partials      379      379           
Flag Coverage Δ
backend 84.48% <ø> (ø)
frontend 88.26% <ø> (ø)

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


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0299256...3df1348. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arkid15r arkid15r added this pull request to the merge queue Jan 25, 2026
Merged via the queue into OWASP:main with commit d6d7ccd Jan 25, 2026
37 checks passed
@preeeetham preeeetham deleted the fix/object-does-not-exist-keyword-arg branch February 8, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix ObjectDoesNotExist exceptions using invalid keyword argument 'msg='

2 participants

Comments