-
Notifications
You must be signed in to change notification settings - Fork 30
Fix DRF Integration Body Processing and API Failure Issues #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@Artui this PR proposes a clean way as it seems to manage the request, but removes part of the logic you coded. Can you please confirm that it does not break your use case ? |
Yeah it will |
But I can keep using the older version for now |
@Artui what use case would this break? If you share more info I can try and figure out a solution that continues to support it, while fixing the 2 issues. |
Well to give you an opinion on the topic :
I don't have enough expertise on DRF internal to judge but I noticed that many issues are solved by giving somehow access to the original request, so maybe we should go this way. I appreciate about this MR that it uses
|
I was attempting to fix the issue of having some arbitrary metadata fields on a django |
Ah that makes sense. In your diagram you said "without data from middleware" -- Can you share more details on what data the middleware adds when an API call comes in that is missing when the Request is passed in via the Tool flow? |
Please i will like to ask, i get an error saying that viewset does not have attribute 'action' when i publishish and try the viewsets endpoint with my agent, again what is the fix for the missing have not been able to see that here. Is it part of a new release? |
Summary
This PR fixes critical bugs in the Django REST Framework integration and adopts a cleaner architectural approach using composition over method patching.
Bugs Fixed
1. Body Parameter Mapping Issue
{"body": {"title": "...", "content": "..."}}
) were not being properly extracted for DRF serializers2. Global ViewSet Patching Breaking Normal HTTP Requests
initialize_request
method was being globally patched on ViewSet classes, affecting ALL requests to those ViewSets, including normal API requestscurl localhost:8000/posts/
) failed withAttributeError: 'WSGIRequest' object has no attribute 'original_request'
Technical Strategy
Instead of trying to bypass or hack DRF's request creation, we pre-process the MCP request into exactly what DRF expects (a simple Django HttpRequest) and then let DRF run its full lifecycle using its intended mechanisms.
The benefits of this approach are:
The potential drawbacks are:
Demo / Testing
Here are screenshots of my really simple Blog Post app (see code here) working with Claude Desktop:





Here's my really simple Blog Post app normal API calls working:

All tests in the bird_counter example app pass: