librelist archives

« back to archive

super object has no attribute handle_error

super object has no attribute handle_error

From:
Michael Montero
Date:
2014-04-08 @ 23:47
Hi!  I have this code:

from flask.ext.restful import Api

class My*Api*(Api):

    def *handle_error*(self, e):

        response = *super*(Api, self).handle_error(e)

        try:

            tinyAPI.dsh().rollback()

        except DataStoreException:

            # A transaction has not been started so nothing can be rolled
back.

            pass

        tinyAPI.dsh().close()

        return response


app = Flask(__name__)

app.config['PROPAGATE_EXCEPTIONS'] = *True*

api = MyApi(app)


When I execute this code, I get this error:

    response = super(Api, self).handle_error(e)

AttributeError: 'super' object has no attribute 'handle_error'


Any idea what I'm missing?

Thanks,

Mike

Re: [flask] super object has no attribute handle_error

From:
Jason G
Date:
2014-04-09 @ 01:31
super(*MyApi*, self).handle_error(e)


On Tue, Apr 8, 2014 at 4:47 PM, Michael Montero <mike@resy.com> wrote:

> Hi!  I have this code:
>
> from flask.ext.restful import Api
>
> class My*Api*(Api):
>
>     def *handle_error*(self, e):
>
>         response = *super*(Api, self).handle_error(e)
>
>         try:
>
>             tinyAPI.dsh().rollback()
>
>         except DataStoreException:
>
>             # A transaction has not been started so nothing can be rolled
> back.
>
>             pass
>
>         tinyAPI.dsh().close()
>
>         return response
>
>
> app = Flask(__name__)
>
> app.config['PROPAGATE_EXCEPTIONS'] = *True*
>
> api = MyApi(app)
>
>
> When I execute this code, I get this error:
>
>     response = super(Api, self).handle_error(e)
>
> AttributeError: 'super' object has no attribute 'handle_error'
>
>
> Any idea what I'm missing?
>
> Thanks,
>
> Mike
>

Re: [flask] super object has no attribute handle_error

From:
Michael Montero
Date:
2014-04-09 @ 01:51
Sorry, I changed the code on the fly. That doesn't fix the issue.

Thank you for the help.


> On Apr 8, 2014, at 9:31 PM, Jason G <gedge@ualberta.ca> wrote:
> 
> super(MyApi, self).handle_error(e)
> 
> 
>> On Tue, Apr 8, 2014 at 4:47 PM, Michael Montero <mike@resy.com> wrote:
>> Hi!  I have this code:
>> 
>> from flask.ext.restful import Api
>> 
>> class MyApi(Api):
>> 
>>     def handle_error(self, e):
>> 
>>         response = super(Api, self).handle_error(e)
>> 
>>         try:
>> 
>>             tinyAPI.dsh().rollback()
>> 
>>         except DataStoreException:
>> 
>>             # A transaction has not been started so nothing can be rolled back.
>> 
>>             pass
>> 
>>         tinyAPI.dsh().close()
>> 
>>         return response
>> 
>> 
>> 
>> app = Flask(__name__)
>> 
>> app.config['PROPAGATE_EXCEPTIONS'] = True
>> 
>> api = MyApi(app)
>> 
>> 
>> 
>> When I execute this code, I get this error:
>> 
>>     response = super(Api, self).handle_error(e)
>> 
>> AttributeError: 'super' object has no attribute 'handle_error'
>> 
>> 
>> 
>> Any idea what I'm missing?
>> 
>> Thanks,
>> 
>> Mike
>> 
> 

Re: [flask] super object has no attribute handle_error

From:
Matthias Urlichs
Date:
2014-04-09 @ 06:11
Hi,

Michael Montero:
> Sorry, I changed the code on the fly. That doesn't fix the issue.
> 
Well, it should (and there's no reason for it not to).

Please make sure that you're really running the code you just edited
(add a "raise Exception" before your super() call and make sure that the
code hits that), and then post the actual code which exhibits the problem.

-- 
-- Matthias Urlichs

Re: [flask] super object has no attribute handle_error

From:
Michael Montero
Date:
2014-04-09 @ 12:39
Jason, as I'm sure you already knew you were right.  I got my wires crossed
obfuscating the code before I emailed it.  This is all settled.

Thanks for the help, guys!

Mike


On Wed, Apr 9, 2014 at 1:31 AM, Jason G <gedge@ualberta.ca> wrote:

> super(*MyApi*, self).handle_error(e)
>
>
> On Tue, Apr 8, 2014 at 4:47 PM, Michael Montero <mike@resy.com> wrote:
>
>> Hi!  I have this code:
>>
>> from flask.ext.restful import Api
>>
>> class My*Api*(Api):
>>
>>     def *handle_error*(self, e):
>>
>>         response = *super*(Api, self).handle_error(e)
>>
>>         try:
>>
>>             tinyAPI.dsh().rollback()
>>
>>         except DataStoreException:
>>
>>             # A transaction has not been started so nothing can be
>> rolled back.
>>
>>             pass
>>
>>         tinyAPI.dsh().close()
>>
>>         return response
>>
>>
>> app = Flask(__name__)
>>
>> app.config['PROPAGATE_EXCEPTIONS'] = *True*
>>
>> api = MyApi(app)
>>
>>
>> When I execute this code, I get this error:
>>
>>     response = super(Api, self).handle_error(e)
>>
>> AttributeError: 'super' object has no attribute 'handle_error'
>>
>>
>> Any idea what I'm missing?
>>
>> Thanks,
>>
>> Mike
>>
>
>

Re: [flask] super object has no attribute handle_error

From:
Kevin Houlihan
Date:
2014-04-09 @ 09:09
Hi Mike,

Since you're using Python 3 I believe you can also just call super without
any arguments, but it should behave identically to what Jason suggested.

However, if you have PROPAGATE_EXCEPTIONS turned on (as you do), then the
base class method will just re-raise most exceptions rather than returning
a Response object, and it will therefore also skip your code. I'm not
really familiar with that configuration variable. If you need it turned on
you could maybe do your own stuff first, then call super.

Regards,
Kevin


On 9 April 2014 00:47, Michael Montero <mike@resy.com> wrote:

> Hi!  I have this code:
>
> from flask.ext.restful import Api
>
> class My*Api*(Api):
>
>     def *handle_error*(self, e):
>
>         response = *super*(Api, self).handle_error(e)
>
>         try:
>
>             tinyAPI.dsh().rollback()
>
>         except DataStoreException:
>
>             # A transaction has not been started so nothing can be rolled
> back.
>
>             pass
>
>         tinyAPI.dsh().close()
>
>         return response
>
>
> app = Flask(__name__)
>
> app.config['PROPAGATE_EXCEPTIONS'] = *True*
>
> api = MyApi(app)
>
>
> When I execute this code, I get this error:
>
>     response = super(Api, self).handle_error(e)
>
> AttributeError: 'super' object has no attribute 'handle_error'
>
>
> Any idea what I'm missing?
>
> Thanks,
>
> Mike
>