Comments (12)
from django.utils.timezone import now
from rest_framework_tracking.base_mixins import BaseLoggingMixin
from rest_framework_tracking.mixins import LoggingMixin
class CustomLoginMixin(LoggingMixin):
def initial(self, request, *args, **kwargs):
self.log = {}
self.log['requested_at'] = now()
self.log['data'] = self._clean_data(request.data)
super(BaseLoggingMixin, self).initial(request, *args, **kwargs)
try:
# Accessing request.data *for the first time* parses the request body, which may raise
# ParseError and UnsupportedMediaType exceptions. It's important not to swallow these,
# as (depending on implementation details) they may only get raised this once, and
# DRF logic needs them to be raised by the view for error handling to work correctly.
data = self.request.data.dict()
except AttributeError:
data = self.request.data
self.log['data'] = self._clean_data(data)
This solution works for me. The main idea replace
request.body with request.data
self.log['data'] = self._clean_data(request.data)
and run parent super
super(BaseLoggingMixin, self).initial(request, *args, **kwargs)
from drf-tracking.
I have solved removing (commenting) the CoreJSONRenderer from the settings.
I hope this helps!
from drf-tracking.
I've downgraded the following packages and now works:
Django from 1.10.5 to 1.10.2
djangorestframework from 3.5.3 to 3.5.1
drf-tracking from 1.1.0 to 1.0.1
maybe this info can help you to solve the bug.
from drf-tracking.
@alfdev Thats for the debugging info!
from drf-tracking.
We are use Django 1.10.5 and djangorestframework 3.4.6 without drf-tracking - same problem
from drf-tracking.
Could you post your settings.py file in your project directory please? I am having the same issue :(
from drf-tracking.
Following my gut feeling to this, it would appear the Request object is not being converted to a DRF-Request object prior to accessing the accepted_renderer
attribute. How and why is really the point of investigation.
Since, LoggingMixin is added per view I would look into the inheritance tree and start eliminating if it's a DRF + DRF-tracking issue or isolated to one library vs the other.
from drf-tracking.
We are having the same problem without drf-tracking:
- Django 1.10.4
- djangorestframework 3.5.3
The problem occurs after updating djangorestframework from < 3 to 3.5.3 and Django from 1.6.5 to 1.10.4
from drf-tracking.
@facconi Thanks for sharing your resolution. Would your solution work everyone or is it specific to your install settings?
If I can find a common thread that is settings oriented maybe I should add notes to the installation guide.
from drf-tracking.
The real solution was that I was using the CoreJSONRenderer without having coreapi in the requirements.txt file.
Installing coreapi fixed the problem!
I think it's a solution that should work for everybody.
from drf-tracking.
None of the fixes mentioned here applied to my scenario with this bug... In my case, the following line seems to be the problem:
Removing that line and letting the super()
call take place correctly sets up the accepted_renderer
property on the request (via a perform_content_negotiation()
inside the initial
of the APIView
class). In the end, self.log['data']
is written again at line 41 of that same function...
Is this a bug or am I missing something?
from drf-tracking.
hi, it seems im late to the party.
Encountered this bug too.
- Scenario : Uploading 4.6mb gif
- Exception Value: Request 'object' has no attribute 'accepted_renderer.'
- Exception Location: .../python3.6/dist-packages/rest_framework/request.py in getattr, line 411
Code:
views.py
class CustomView(LoggingMixin, APIView):
def post(self, request, *args, **kwargs):
# do something here.
I do not do anything overriding since I want to use the default.
But the thing here is when i tried to upload its causes the bug.
Method 1:
- Removing LoggingMixin
It works. Though why do I do that?
Method 2:
- Upon reading the error I stumbled with.
During handling of the above exception (Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.), another exception occurred:... - DATA_UPLOAD_MAX_MEMORY_SIZE pertains to settings.py which by default is 2.5mb 2.6m-ish something on docs.
solution: change the size. e.g DATA_UPLOAD_MAX_MEMORY_SIZE = 4mil-ish or None (is it good)?
Though its weird why in APIView itself does not trigger that error (w/o LoggingMixin) ?
btw I had nginx setup which :
server:{
client_max_body_size 10M;
}
or maybe this one /\ is the answer to my confusion.
Just an Update:
nginx had nothing to do it throws another error
solution: change the size DATA_ larger than the nginx and let nginx handle the error.
so if you stumble with the same issue as mine hopefully this help . And much apprecidated if someone can answer that kind of behavior
from drf-tracking.
Related Issues (20)
- Log Construction HOT 1
- LogginMixin not gets called with ModelViewSet in Django 2.0.4 HOT 3
- Migrations conflict HOT 4
- When I get an api and there will always be 2 logs at a time HOT 1
- How to do drf tracking write in async thread HOT 1
- django 2 compatible HOT 3
- Can we track django-oauth-toolkit client?
- Failed Clean data when uploading file as form-data HOT 2
- Only last params value is captured if multiple query params are sent with same key
- why this line is needed? HOT 4
- UnicodeDecodeError on python 2.7 / django 1.11 HOT 2
- Feature Request: Skip logging the response HOT 1
- PIP (pypi) is not updated HOT 5
- Add city & country data to the log HOT 1
- Some requests are not recorded HOT 2
- requested_at and remote_addr fields in base_model are not null HOT 1
- Fix missing query_params on Put/Post/Patch requests. Update tox tests to include django 2.2.6 and drf 3.10.3 versions HOT 5
- Can we publish a new release? HOT 14
- Azure proxy config throws psycopg2 exception HOT 6
- Django version 3.x has not "django.utils.six" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-tracking.