Issue: ImportWarning on PooledPostgresqlExtDatabase
Author: alecgerona
State: closed
Created: 2020-11-10 18:28:20

Hi all so we're using the query builder feature (not the ORM at all) of peewee and it's been great so far. Been using it with fastapi and it's been working great until the 3.14.0 update. Now we're getting the following issue: 
```
tests/test_lib/integration/test_pagination.py:3: in <module>
    from app.user.models import User, UserPagination
app/user/models.py:45: in <module>
    User = __User()
lib/table.py:54: in __init__
    from app.database import db
app/database.py:2: in <module>
    from lib.database import RetryableDatabase
lib/database.py:17: in <module>
    from playhouse.pool import PooledPostgresqlExtDatabase
venv/lib/python3.8/site-packages/playhouse/pool.py:305: in <module>
    from playhouse.sqlite_ext import SqliteExtDatabase
venv/lib/python3.8/site-packages/playhouse/sqlite_ext.py:19: in <module>
    from playhouse._sqlite_ext import (
playhouse/_sqlite_ext.pyx:1: in init playhouse._sqlite_ext
    ???
E   ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
```
Can anyone shed light on this? Rolling back to 3.13 fixes the issue. 

That's odd. The line you're referencing, 305, is wrapped in a try/except on `ImportError`, as is the code in `sqlite_ext.py` which attempts to import from the C extension. This doesn't seem to be an error, but rather a warning?

The `pyx` file is the cython source file, which gets compiled into a C extension. Is your code trying to read the pyx file, or what is going on there?

Okay so for more context the error only happens when `pytest` is run since the file in question that imports `PooledPostgresqlExtDatabase ` is imported in `pytest`'s conftest.py. Running it through uvicorn works otherwise. 

I think this may be the related issue https://github.com/cython/cython/issues/1720 - I'm not sure why this occurs only for 3.14 but not 3.13.3, though?

Probably? What should be a workaround for this? 

I don't see anything in the diff that seems relevant to this issue: https://github.com/coleifer/peewee/compare/3.13.3...3.14.0

Also, as far as I can tell this isn't a bug, but rather you're receiving a warning during testing. You might try recompiling, or upgrading cython and rebuilding?

Hmm. This happens on a fresh install/run on a CI though. Still a cython issue? 

I don't know, honestly. I don't see the issue running the peewee tests https://travis-ci.org/github/coleifer/peewee and I really don't see anything between versions 3.13.3 and 3.14.0 that seems relevant.

@coleifer found an issue related to this: https://github.com/pytest-dev/pytest/issues/4423 and it seems like it is Cython issue that and he ended up building it with a newer version of Cython to get it working. Might help. 

@coleifer more info: when I install peewee 3.14.0 from source, it works no problem. So maybe something else happened when 3.14.0 was released in pypi? 

Final context to those who might stumble upon this: peewee@3.14.0 works in Python 3.9 and not on 3.8. I haven't tested for lower versions. However, 3.14.1 and 3.14.2 works on both 3.9 and 3.8. I still think that there was something wrong with how 3.14.0 was built.