Zappa icon indicating copy to clipboard operation
Zappa copied to clipboard

SQLite ImproperlyConfigured exception

Open ebridges opened this issue 5 years ago • 7 comments

Exception:

raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)

Expected Behavior

An HTTP GET to the API Gateway URL should show the default Django "welcome" page, as is shown when invoking open http://127.0.0.1:8080 on a new Django project.

Actual Behavior

$ zappa deploy
...
Calling deploy for stage dev..
Creating testing-dev-ZappaLambdaExecutionRole IAM Role..
Creating zappa-permissions policy on testing-dev-ZappaLambdaExecutionRole IAM Role.
Downloading and installing dependencies..
 - sqlite==python3: Using precompiled lambda package
'python3.7'
Packaging project as zip.
Uploading testing-dev-1559325136.zip (14.8MiB)..
100%|██████████████████████████████████████████████| 15.6M/15.6M [00:07<00:00, 1.93MB/s]
Scheduling..
Scheduled testing-dev-zappa-keep-warm-handler.keep_warm_callback with expression rate(4 minutes)!
Uploading testing-dev-template-1559325160.json (1.6KiB)..
100%|██████████████████████████████████████████████| 1.60K/1.60K [00:00<00:00, 16.5KB/s]
Waiting for stack testing-dev to create (this can take a bit)..
 75%|███████████████████████████████████████             | 3/4 [00:13<00:05,  5.59s/res]
Deploying API Gateway..
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 500 response code.
$ zappa tail
...
[1559325174623] [ERROR] ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3    raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
...
$ curl https://qzgbmw28gk.execute-api.us-east-1.amazonaws.com/dev
"{'message': 'An uncaught exception happened while servicing this request. You can investigate this with the `zappa tail` command.', 'traceback': ['Traceback (most recent call last):\\n', '  File \"/var/task/handler.py\", line 531, in handler\\n    with Response.from_app(self.wsgi_app, environ) as response:\\n', '  File \"/var/task/werkzeug/wrappers/base_response.py\", line 287, in from_app\\n    return cls(*_run_wsgi_app(app, environ, buffered))\\n', '  File \"/var/task/werkzeug/test.py\", line 1119, in run_wsgi_app\\n    app_rv = app(environ, start_response)\\n', \"TypeError: 'NoneType' object is not callable\\n\"]}"

Steps to Reproduce

mkdir testing
cd testing
poetry init --name=testing --author='[email protected]' 
poetry add django zappa
source $(dirname $(poetry run which python))/activate # activate venv
django-admin startproject myproject .
python manage.py runserver
open http://127.0.0.1:8000/ # confirm all works
zappa init
zappa deploy dev
zappa tail
zappa status

Your Environment

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.4
BuildVersion:	18E226
$ poetry --version
Poetry 0.12.11
$ python --version
Python 3.7.0
$ django-admin --version
2.2.1
$ zappa --version
0.48.2
Complete list of packages installed in venv
$ poetry show
argcomplete         1.9.3    Bash tab completion for argparse
boto3               1.9.159  The AWS SDK for Python
botocore            1.12.159 Low-level, data-driven core of boto 3.
certifi             2019.3.9 Python package for providing Mozilla's CA Bundle.
cfn-flip            1.2.0    Convert AWS CloudFormation templates between JSON and YAML formats
chardet             3.0.4    Universal encoding detector for Python 2 and 3
click               7.0      Composable command line interface toolkit
django              2.2.1    A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
docutils            0.14     Docutils -- Python Documentation Utilities
durationpy          0.5      Module for converting between datetime.timedelta and Go's Duration strings.
future              0.16.0   Clean single-source support for Python 3 and 2
hjson               3.0.1    Hjson, a user interface for JSON.
idna                2.8      Internationalized Domain Names in Applications (IDNA)
jmespath            0.9.3    JSON Matching Expressions
kappa               0.6.0    A CLI tool for AWS Lambda developers
lambda-packages     0.20.0   AWS Lambda Packages
placebo             0.9.0    Make boto3 calls that look real but have no effect
python-dateutil     2.6.1    Extensions to the standard Python datetime module
python-slugify      1.2.4    A Python Slugify application that handles Unicode
pytz                2019.1   World timezone definitions, modern and historical
pyyaml              5.1      YAML parser and emitter for Python
requests            2.22.0   Python HTTP for Humans.
s3transfer          0.2.0    An Amazon S3 Transfer Manager
six                 1.12.0   Python 2 and 3 compatibility utilities
sqlparse            0.3.0    Non-validating SQL parser
toml                0.10.0   Python Library for Tom's Obvious, Minimal Language
tqdm                4.19.1   Fast, Extensible Progress Meter
troposphere         2.4.7    AWS CloudFormation creation library
unidecode           1.0.23   ASCII transliterations of Unicode text
urllib3             1.25.3   HTTP library with thread-safe connection pooling, file post, and more.
werkzeug            0.15.4   The comprehensive WSGI web application library.
wheel               0.33.4   A built-package format for Python.
wsgi-request-logger 0.4.6    Apache-like combined logging for WSGI Web Applications
zappa               0.48.2   Server-less Python Web Services for AWS Lambda and API Gateway

Zappa settings:

{
    "dev": {
        "aws_region": "us-east-1",
        "django_settings": "myproject.settings",
        "profile_name": "ebridges@roja",
        "project_name": "testing",
        "runtime": "python3.7",
        "s3_bucket": "mybucket"
    }
}

ebridges avatar May 31 '19 18:05 ebridges

Having the same problem, but I am using pip on windows 10.

TopazJ avatar Jun 27 '19 22:06 TopazJ

Figured it out, it has something to do with using Django version 2.2 or newer. Django 2.1.9 works just fine.

TopazJ avatar Jun 28 '19 18:06 TopazJ

go to venv/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py

change

def check_sqlite_version(): if Database.sqlite_version_info < (3, 8, 3): raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' %

to

def check_sqlite_version(): if Database.sqlite_version_info < (3, 8, 3): pass # raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)

also applies to mysql and other databases. zappa hasn't updated im guessing since then

valeriozhang avatar Mar 31 '20 15:03 valeriozhang

@valeriozhang This worked great for me. Thanks!

Jattwood90 avatar Apr 05 '21 16:04 Jattwood90

I got myself a working setup by using @valeriozhang's tip but took it further by scripting it into my CI (building an MVP without DB requirements, yet). To save other's time, here's the oneliner;

# VIRTUAL_ENV is normally ve or venv
find $VIRTUAL_ENV/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py -type f -exec sed -i '' -e "s/^check_sqlite_version()/#check_sqlite_version()/" {} \;

kulor avatar Sep 14 '21 21:09 kulor

This still happens in the newest version of Django (v4.2+ and v5)

Downgrading to a version multiple versions lesser is clearly not an option; and editing deployed code after the fact violates security and compliance.

A fix - or even just an explanation on why you cant fix it - would be great. There seems to be a of of finger pointing going on when I google, but nobody seems to have the leadership skills to solve this issue for everybody, so I would rather do that.

What does the zappa team need to ship a fix? Is zappa the correct spot for the fix?

duaneking avatar Oct 03 '23 21:10 duaneking

@duaneking this project is now hosted under https://github.com/zappa/Zappa you might try investigating there.

ebridges avatar Oct 04 '23 01:10 ebridges