Issue: No sqlite3 causes issue on import of PaginatedQuery
Author: savraj
State: closed
Created: 2017-03-11 22:13:43

I use MySQL and don't need sqlite3.

`from playhouse.flask_utils import PaginatedQuery`

gives me this error:
```
FTS_VER = sqlite3.sqlite_version_info[:3] >= (3, 7, 4) and 'FTS4' or 'FTS3'
AttributeError: 'NoneType' object has no attribute 'sqlite_version_info'
```
[line that causes error](https://github.com/coleifer/peewee/blob/f3795767f7b46c8b5335ea0257df2a1d269fc85b/playhouse/sqlite_ext.py#L70)

I'm in the google app engine development environment, so I believe sqlite3 gets set to `None` when the `ImportError` is caught.  My hacky fix is an if/else setting `FTS_VER` to `None` if there's no `sqlite3`.

Aha, thanks! Should be fixed by f68ff7fb30a149fe9df8050b8001a1b4d3636bec

This fix didn't work -- the error still happens because an AttributeError is the problem, the fix catches an ImportError.

If you look at the file `sqlite_ext.py`, line 54 `from peewee import sqlite3`
Then looking at lines 155-165 in `peewee.py` `sqlite3` gets set to `None` if I don't have pysq3 or sqlite3, which I apparently don't have. :)

Again super appreciative of all the help and quick fixes. Thanks again.

-s



Is the traceback the same?

```
FTS_VER = sqlite3.sqlite_version_info[:3] >= (3, 7, 4) and 'FTS4' or 'FTS3'
AttributeError: 'NoneType' object has no attribute 'sqlite_version_info'
```

Yes, I believe so, here's the full traceback (using a fresh pip install of 2.9.1):

```
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "XXXX/main.py", line 20, in <module>
    from controllers.XXXX import XXXX
  File "XXXX/controllers/XXXX.py", line 19, in <module>
    from playhouse.flask_utils import PaginatedQuery
  File "XXXX/lib/playhouse/flask_utils.py", line 12, in <module>
    from playhouse.db_url import connect as db_url_connect
  File "XXXX/lib/playhouse/db_url.py", line 7, in <module>
    from playhouse.pool import PooledMySQLDatabase
  File "XXXX/lib/playhouse/pool.py", line 279, in <module>
    from playhouse.sqlite_ext import SqliteExtDatabase
  File "XXXX/lib/playhouse/sqlite_ext.py", line 70, in <module>
    FTS_VER = sqlite3.sqlite_version_info[:3] >= (3, 7, 4) and 'FTS4' or 'FTS3'
AttributeError: 'NoneType' object has no attribute 'sqlite_version_info'
```

Could you try the latest commit, fc84b65ff3a02eba05ccf63aead2de38412ac9c3 and let me know how it works? Sorry for the bad fix!

Hi -- just checking in. This fix hasn't made it in to the latest version yet, afaict, on install from pip. I do see it is in the master repo, though.

It should be in 2.9.2.

got it! thanks!

On Thu, Apr 13, 2017 at 8:34 PM, Charles Leifer <notifications@github.com>
wrote:

> It should be in 2.9.2.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/coleifer/peewee/issues/1218#issuecomment-294055750>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAXqHY27cuB3eDVczU2JPKgVRlJ7niueks5rvr8mgaJpZM4MaWl5>
> .
>



-- 
Savraj Singh
Founder, Wattvision.com
609.540.2204 • twitter/gtalk/skype: savraj
savraj@wattvision.com


Still facing the sqlite3 issue, even though we are using peewee==2.10.1. Please advice at the earliest. Thank you.

Error Stack Trace -
'NoneType' object has no attribute 'sqlite_version_info': AttributeError
Traceback (most recent call last):
File "/var/task/handler.py", line 511, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 242, in lambda_handler
return handler.handler(event, context)
File "/var/task/handler.py", line 335, in handler
app_function = self.import_module_and_get_function(whole_function)
File "/var/task/handler.py", line 233, in import_module_and_get_function
app_module = importlib.import_module(module)
File "/var/lang/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 978, in _gcd_import
File "", line 961, in _find_and_load
File "", line 950, in _find_and_load_unlocked
File "", line 655, in _load_unlocked
File "", line 678, in exec_module
File "", line 205, in _call_with_frames_removed
File "/var/task/schedular.py", line 16, in 
import models_postgres as models
File "/var/task/models_postgres.py", line 4, in 
from playhouse.db_url import connect
File "/var/task/playhouse/db_url.py", line 118, in 
from playhouse.berkeleydb import BerkeleyDatabase
File "/var/task/playhouse/berkeleydb.py", line 10, in 
sqlite3_lib_version = sqlite3.sqlite_version_info
AttributeError: 'NoneType' object has no attribute 'sqlite_version_info'

8ba62478f7ce4fc3890fad0d1c42e851a382bdd4

Thanks for the traceback, that helped me narrow it down.