zappa / Zappa

Serverless Python
https://zappa.ws/zappa
MIT License
3.35k stars 362 forks source link

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

Closed jneves closed 2 years ago

jneves commented 3 years ago

Originally from: https://github.com/Miserlou/Zappa/issues/2165 by rafrasenberg

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
seanpar203 commented 3 years ago

I'm experiencing this issue follow the most basic guide ever:

https://blog.logrocket.com/zappa-and-aws-lambda-for-serverless-django/

Requirements

argcomplete==1.12.3
asgiref==3.3.4
boto3==1.17.66
botocore==1.20.66
certifi==2020.12.5
cfn-flip==1.2.3
chardet==4.0.0
click==7.1.2
Django==2.2.21
durationpy==0.5
future==0.18.2
hjson==3.0.2
idna==2.10
importlib-metadata==4.0.1
jmespath==0.10.0
kappa==0.6.0
pep517==0.10.0
pip-tools==6.1.0
placebo==0.9.0
python-dateutil==2.8.1
python-slugify==5.0.0
pytz==2021.1
PyYAML==5.4.1
requests==2.25.1
s3transfer==0.4.2
six==1.16.0
sqlparse==0.4.1
text-unidecode==1.3
toml==0.10.2
tqdm==4.60.0
troposphere==2.7.1
typing-extensions==3.10.0.0
urllib3==1.26.4
Werkzeug==0.16.1
wsgi-request-logger==0.4.6
zappa==0.52.0
zipp==3.4.1

Zappa Config

{
    "dev": {
        "django_settings": "amazing.settings",
        "profile_name": "default",
        "project_name": "amazing",
        "runtime": "python3.7",
        "s3_bucket": "zappa-bbbolcxgn",
        "aws_region": "us-east-1"
    }
}

Error

[START] RequestId: 3e04d5ec-4550-4f8e-84ad-85fe9d1a0684 Version: $LATEST
[DEBUG] 2021-05-05T15:48:19.990Z 3e04d5ec-4550-4f8e-84ad-85fe9d1a0684 Zappa Event: {'manage': 'shell'}
[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")
monkut commented 2 years ago

This is a sign that something is not configured correctly in django. Make sure you can runserver locally with django.

closing old migrated issue.