Skip to content

Handle non-mapping request data in update_traits#7953

Open
m-husnain-dev wants to merge 2 commits into
Flagsmith:mainfrom
m-husnain-dev:main
Open

Handle non-mapping request data in update_traits#7953
m-husnain-dev wants to merge 2 commits into
Flagsmith:mainfrom
m-husnain-dev:main

Conversation

@m-husnain-dev

Copy link
Copy Markdown

Description

This change prevents a crash when request.data is not a mapping before unpacking it with **request.data in update_traits().

Instead of raising a TypeError, the endpoint now returns a proper ValidationError for invalid request payloads.

Fixes #7951

@m-husnain-dev m-husnain-dev requested a review from a team as a code owner July 6, 2026 18:46
@m-husnain-dev m-husnain-dev requested review from emyller and removed request for a team July 6, 2026 18:46
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

@m-husnain-dev 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 Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a2eec89b-3dcd-48ad-ae0d-c5aeb4b98fb2

📥 Commits

Reviewing files that changed from the base of the PR and between da194ca and 9932350.

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

📝 Walkthrough

Walkthrough

This change adds a validation check to the update_traits method in EdgeIdentityViewSet. Before processing trait data, the code now verifies that request.data is a dictionary (JSON object). If it is not, a ValidationError is raised with a descriptive message, preventing further processing of malformed payloads.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Changes

File Change Summary
api/edge_api/identities/views.py Added a type check in update_traits to raise ValidationError when request.data is not a dictionary.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant EdgeIdentityViewSet
    participant TraitModel

    Client->>EdgeIdentityViewSet: PUT/POST trait data
    EdgeIdentityViewSet->>EdgeIdentityViewSet: check isinstance(request.data, dict)
    alt is dict
        EdgeIdentityViewSet->>TraitModel: construct trait instances
        TraitModel-->>EdgeIdentityViewSet: validated traits
        EdgeIdentityViewSet-->>Client: success response
    else not dict
        EdgeIdentityViewSet-->>Client: ValidationError
    end
Loading

Related issues: None specified.

Related PRs: None specified.

Suggested labels: api, bug-fix

Suggested reviewers: None specified.


🐰 A tiny check before the trait,
Guards the gate, keeps data straight,
If not a dict, it won't proceed,
A validation error's what you'll need,
Hops of safety, small but great!


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.

update-traits crash when traits malformed

1 participant