alexmclarty / mirror

A simple app for mock API creation
3 stars 0 forks source link

Enabling DEBUG mode causes AssertionError #6

Open alexmclarty opened 5 years ago

alexmclarty commented 5 years ago

Enabling DEBUG mode causes the app to throw an AssertionError:

AssertionError: A setup function was called after the first request was handled. This usually indicates a bug in the application where a module was not imported and decorators or other functionality was called too late. To fix this make sure to import all your view modules, database models and everything related at a central place before the application starts serving requests.

I think this is something to do with DEBUG mode firing a request first. This does not occur in production mode.

See other issues for hints: https://github.com/ga4gh/ga4gh-server/issues/791

alexmclarty commented 5 years ago

app.py L53:

def setupmethod(f):
    """Wraps a method so that it performs a check in debug mode if the
    first request was already handled.
    """
    def wrapper_func(self, *args, **kwargs):
        if self.debug and self._got_first_request:
            raise AssertionError('A setup function was called after the '
                'first request was handled.  This usually indicates a bug '
                'in the application where a module was not imported '
                'and decorators or other functionality was called too late.\n'
                'To fix this make sure to import all your view modules, '
                'database models and everything related at a central place '
                'before the application starts serving requests.')
        return f(self, *args, **kwargs)
    return update_wrapper(wrapper_func, f)

Commenting out the if self.debug and self._got_first_request works even in DEBUG mode. I wonder what this function is protecting?

I'm assuming that it's us calling add_url_rule in an endpoint when running DEBUG mode that causes the problem. But I don't know why...