Miserlou/Zappa

[ERROR] RuntimeError: populate() isn't reentrant

Opened this issue · 2 comments

I am trying to deploy a Django project with Zappa and a PostgreSQL database on Amazon AWS RDS but I am running into this error:

$ zappa manage dev create_db 
[START] RequestId: ac91cbb6-9026-44d5-9136-3e4db8c0878c Version: $LATEST
[DEBUG] 2020-09-22T11:16:57.834Z ac91cbb6-9026-44d5-9136-3e4db8c0878c Zappa Event: {'manage': 'create_db'}
[ERROR] RuntimeError: populate() isn't reentrant
Traceback (most recent call last):
  File "/var/task/handler.py", line 609, in lambda_handler
    return LambdaHandler.lambda_handler(event, context)
  File "/var/task/handler.py", line 243, in lambda_handler
    return handler.handler(event, context)
  File "/var/task/handler.py", line 404, in handler
    app_function = get_django_wsgi(self.settings.DJANGO_SETTINGS)
  File "/var/task/zappa/ext/django_zappa.py", line 20, in get_django_wsgi
    return get_wsgi_application()
  File "/var/task/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/var/task/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/var/task/django/apps/registry.py", line 83, in populate
    raise RuntimeError("populate() isn't reentrant")[END] RequestId: ac91cbb6-9026-44d5-9136-3e4db8c0878c
[REPORT] RequestId: ac91cbb6-9026-44d5-9136-3e4db8c0878c
Duration: 2.28 ms
Billed Duration: 100 ms
Memory Size: 512 MB
Max Memory Used: 101 MB

Error: Unhandled error occurred while invoking command.

Pretty meaningless error. I google'd this and tried some of the solutions in other tickets but could not resolve this. I tried psycopg2 and psycopg2-binary but both no luck. Did anyone ever solve this? Because all the articles/issues covering this are old and outdated.

Zappa settings:

{
  "dev": {
    "aws_region": "eu-central-1",
    "django_settings": "dserverless.settings",
    "profile_name": "default",
    "project_name": "dserverless",
    "runtime": "python3.8",
    "s3_bucket": "django-serverless",
    "vpc_config": {
      "SubnetIds": ["subnet-2cef773346", "subnet-023527a", "subnet-6agbcb21"],
      "SecurityGroupIds": ["sg-87325d"]
    }
  }
}

The DB command:

class Command(BaseCommand):
    help = 'Creates the initial database'

    def handle(self, *args, **options):
        self.stdout.write(self.style.SUCCESS('Starting db creation'))

        dbname = settings.DATABASES['default']['NAME']
        user = settings.DATABASES['default']['USER']
        password = settings.DATABASES['default']['PASSWORD']
        host = settings.DATABASES['default']['HOST']

        con = None
        con = connect(dbname=dbname, user=user, host=host, password=password)
        con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
        cur = con.cursor()
        cur.execute('CREATE DATABASE ' + dbname)
        cur.close()
        con.close()

        self.stdout.write(self.style.SUCCESS('All Done'))

Pip freeze:

appdirs==1.4.3
argcomplete==1.12.0
asgiref==3.2.10
autopep8==1.5.4
boto3==1.15.2
botocore==1.18.2
CacheControl==0.12.6
certifi==2019.11.28
cfn-flip==1.2.3
chardet==3.0.4
click==7.1.2
colorama==0.4.3
contextlib2==0.6.0
distlib==0.3.0
distro==1.4.0
Django==3.1.1
django-s3-storage==0.13.4
durationpy==0.5
future==0.18.2
hjson==3.0.2
html5lib==1.0.1
idna==2.8
ipaddr==2.2.0
jmespath==0.10.0
kappa==0.6.0
lockfile==0.12.2
msgpack==0.6.2
packaging==20.3
pep517==0.8.2
pip-tools==5.3.1
placebo==0.9.0
progress==1.5
psycopg2-binary==2.8.6
pycodestyle==2.6.0
pyparsing==2.4.6
python-dateutil==2.6.1
python-slugify==4.0.1
pytoml==0.1.21
pytz==2020.1
PyYAML==5.3.1
requests==2.22.0
retrying==1.3.3
s3transfer==0.3.3
six==1.14.0
sqlparse==0.3.1
text-unidecode==1.3
toml==0.10.1
tqdm==4.49.0
troposphere==2.6.2
urllib3==1.25.8
webencodings==0.5.1
Werkzeug==0.16.1
wsgi-request-logger==0.4.6
zappa==0.51.0

Any particular reason you don't want to just log into the RDS instance? You'll probably need to eventually anyways.

@rafrasenberg have you managed to solve this? Facing the same issue