Skip to content

Connection closed after first commit #8

Description

@cpowers

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions