Skip to content

fix: return 404 instead of 500 for invalid identity_pk in feature states - #8558

Open
PrakashWebDevX wants to merge 1 commit into
Flagsmith:mainfrom
PrakashWebDevX:patch-1
Open

PrakashWebDevX wants to merge 1 commit into
Flagsmith:mainfrom
PrakashWebDevX:patch-1

Conversation

@PrakashWebDevX

Copy link
Copy Markdown

fix: return 404 instead of 500 for invalid identity_pk in feature states

IdentityFeatureStateViewSet.get_queryset() passed the raw identity_pk
URL kwarg directly into a queryset filter, causing Django's ORM to
raise an unhandled ValueError when the value wasn't a valid integer
(e.g. a malformed or non-numeric ID).

Use get_object_or_404 to resolve the identity first, matching the
existing pattern already used in this same class's all() action.

Fixes #7361

…tes IdentityFeatureStateViewSet.get_queryset() passed the raw identity_pk URL kwarg directly into a queryset filter, causing Django's ORM to raise an unhandled ValueError when the value wasn't a valid integer (e.g. a malformed or non-numeric ID). Use get_object_or_404 to resolve the identity first, matching the existing pattern already used in this same class's `all()` action. Fixes Flagsmith#7361
@PrakashWebDevX
PrakashWebDevX requested a review from a team as a code owner September 20, 2026 12:44
@PrakashWebDevX
PrakashWebDevX requested review from emyller and removed request for a team September 20, 2026 12:44
@vercel

vercel Bot commented Sep 20, 2026

Copy link
Copy Markdown

@PrakashWebDevX is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label Sep 20, 2026
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: f71d96b7-1b29-448b-ad35-fa324925c0c9

📥 Commits

Reviewing files that changed from the base of the PR and between 190c645 and 95a92f8.

📒 Files selected for processing (1)
  • api/features/views.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

IdentityFeatureStateViewSet.get_queryset now resolves the identity from the identity_pk URL parameter with get_object_or_404. It then filters feature states by the resolved identity. Requests for a non-existent identity now return a 404 instead of an empty result.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~5 minutes

Severity of issue fixed: Medium

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

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

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API crash because of bad URL parameters

1 participant