sdispater / flask-orator

Adds Orator support to your Flask application
MIT License
74 stars 13 forks source link

Connection closed after first commit #8

Open cpowers opened 7 years ago

cpowers commented 7 years ago

When using flask-orator I am able to make a POST to an endpoint that saves a new model object but after a few requests (depending on the number of worker processes) I will start getting this error.

AttributeError: 'NoneType' object has no attribute 'autocommit'

I tracked the problem down to the fact the connection is closed on teardown of the app context but when that happens any new request that gets that same process is unable to save any data due to the way a connection is returned in the default DatabaseManager implementation in orator.

I worked around this issue by creating a new implementation of DatabaseManager that removes the connection from its internal storage so that when a new connection is requested it actually creates a new one. See the updated disconnect function from DatabaseManager below

def disconnect(self, name=None): if name is None: name = self.get_default_connection() logger.debug("Disconnecting %s" % name) if name in self._connections: self._connections[name].disconnect() del self._connections[name]

I just added this line

del self._connections[name]

Oddly enough this doesn't seem to be a problem when just reading data from the database.

I'm not sure if this is really a bug in orator or flask-orator so I thought I would start by creating the issue here.

zardilior commented 5 years ago

I had the same problem multiple times

old-adapdr commented 4 years ago

Same problem here.