After updating to 2.8.8 from 2.8.5, started seeing a bug that occurs on 2.8.7 as well
I bumped into this too. The commit that causes this is 9e76c999868197a4911fa2fa457c50ab42431ff1, which came about because of #1108.

The pull request explains why the commit is necessary and how you can solve your problem, but in short use `our_db.get_conn()` instead of `our_db.connect()`.

If this is a permanent solution then the docs should probably be updated (especially the [Adding Request Hooks](http://docs.peewee-orm.com/en/latest/peewee/database.html#adding-request-hooks) section), but I'll leave that up to @coleifer to decide. Thanks for the quick reply Matt, much appreciated! Also you can use [`FlaskDB`](https://github.com/coleifer/peewee/blob/master/playhouse/flask_utils.py#L78) from `playhouse.flask_utils` module Related: Where are the release notes for 2.8.5 through 2.8.8? :) > In our boilerplate Flask connection open/close code (copied from the docs), and it happens only on the first time our server comes up running on the google app engine development server.

Are you doing anything with the database at module-scope? For instance, creating tables, or anything that might unintentionally cause a connection to be opened? @flother -- thanks, by the way, for providing the details on the commit and a workaround.

The change prevents connections from being opened and then subsequently not closed because the reference to them was overwritten with a 2nd connection.

The OperationalError is clue-ing you in to a spot in your code where you've already got an open connection for the given thread and are trying to open a new one on top of it. Like I said -- check for database accesses at module scope or during application startup, those are likely to be the culprits.

As for using `get_conn()` in the hooks, I still think it is advisable to use `connect()`, because in most applications an exception would only be raised because the developer had forgotten to close one somewhere...which seems like a bug.
Hi Charles and team,

First, many thanks for creating an AMAZING ORM -- we depend on it and we love its simplicity.

So the weird bug is, we see a
`OperationalError('Connection already open')`

In our boilerplate Flask connection open/close code (copied from the docs), and it happens only on the first time our server comes up running on the google app engine development server.

```
# set up DB handling
@app.before_request
def connect_db():
    our_db.connect()  # this raises an operational error only on the first request

@app.teardown_request
def close_db(exc):
    if not our_db.is_closed():
        our_db.close()
```

Thing is, I can move back to 2.8.5 and everything works normally -- no OperationalError is raised.  Though we looked at the commits between .5 and .8 and didn't see anything unusual. Your insight is appreciated! Thank you in advance, and again, we love Peewee!!! (Our temporary fix is sticking with 2.8.5)

-savraj
