Skip to content

Commit

Permalink
Fix random RecursionError crash in tests
Browse files Browse the repository at this point in the history
Tests crashed randomly with a RecursionError,  because a random secret key gets generated that starts with a $ which is a special prefix in django-environ for some kind of proxied value. This simply replaces any $ in generated keys with %.
  • Loading branch information
Kurocon authored Jul 22, 2024
1 parent 3efe909 commit 1f6d213
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion amelie/settings/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
# Initialize an env object for `django-environ`
env = environ.Env()

# Proxy function for get_random_secret_key that replaces $ with % (because $ has a special function in django-environ)
def get_random_secret_key_no_dollar():
s = get_random_secret_key()
return s.replace('$', '%')

# Set base path of the project, to build paths with.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent

Expand Down Expand Up @@ -238,7 +243,7 @@
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Make this unique, and don't share it with anybody.
SECRET_KEY = env('DJANGO_SECRET_KEY', default=get_random_secret_key())
SECRET_KEY = env('DJANGO_SECRET_KEY', default=get_random_secret_key_no_dollar())


###
Expand Down

0 comments on commit 1f6d213

Please sign in to comment.