python-django icon indicating copy to clipboard operation
python-django copied to clipboard

Error: object has no attribute 'META'

Open julidr opened this issue 6 years ago • 3 comments

Hi! I got the following error 'GetExampleView' object has no attribute 'META' when i implement @tracing.trace() inside a class that inherits from any kind of APiView related model.

class GetExampleView(APIView):
    @tracing.trace()
    def get(self, request):
        pass

I don't know if the fact that it was used inside a class and the attribute self (which is the GetExampleView) was sent before request caused this error.

There is any kind of support when this is implemented inside classes? i noticed that all examples where used directly in functions that received request as first param or maybe i'm doing something wrong with the implementation.

julidr avatar Mar 11 '19 14:03 julidr

@julidr did you solve this?

crosvera avatar Jun 01 '21 17:06 crosvera

@julidr the problem is that @tracing.trace() assumes that you are using functions as views, so the decorator expects that the first parameter is a request object, but instead, your approach here is classes as views, then the first parameter is self which is the GetExampleView instance object.

I had forked this project and created a new branch where I added a new decorator @tracing.another_trace('method_name', is_method=True), which allows you to trace commons functions and methods. https://github.com/crosvera/python-django/tree/another_trace

crosvera avatar Jun 03 '21 22:06 crosvera

I know this is super old, but just wrap in method_decorator, so @method_decorator(tracing.trace())

jamesshaw49 avatar Aug 23 '24 04:08 jamesshaw49