Code Monkey home page Code Monkey logo

Comments (12)

RuslanButko avatar RuslanButko commented on July 30, 2024 3
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.

facconi avatar facconi commented on July 30, 2024 2

I have solved removing (commenting) the CoreJSONRenderer from the settings.
I hope this helps!

from drf-tracking.

alfdev avatar alfdev commented on July 30, 2024

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.

avelis avatar avelis commented on July 30, 2024

@alfdev Thats for the debugging info!

from drf-tracking.

lexapi avatar lexapi commented on July 30, 2024

We are use Django 1.10.5 and djangorestframework 3.4.6 without drf-tracking - same problem

from drf-tracking.

texascloud avatar texascloud commented on July 30, 2024

Could you post your settings.py file in your project directory please? I am having the same issue :(

from drf-tracking.

avelis avatar avelis commented on July 30, 2024

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.

i4s-acarrasco avatar i4s-acarrasco commented on July 30, 2024

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.

avelis avatar avelis commented on July 30, 2024

@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.

facconi avatar facconi commented on July 30, 2024

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.

rnegron avatar rnegron commented on July 30, 2024

None of the fixes mentioned here applied to my scenario with this bug... In my case, the following line seems to be the problem:

self.log['data'] = self._clean_data(request.body)

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.

Kiel-Hyre avatar Kiel-Hyre commented on July 30, 2024

hi, it seems im late to the party.
Encountered this bug too.

  1. Scenario : Uploading 4.6mb gif
  2. Exception Value: Request 'object' has no attribute 'accepted_renderer.'
  3. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.