Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/.env-local
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DATABASE_URL=postgresql://postgres:password@localhost:5432/flagsmith
DJANGO_SETTINGS_MODULE=app.settings.local
PYTEST_ADDOPTS=--cov . --cov-report html -n auto
USE_SECURE_COOKIES=False
COOKIE_SAME_SITE=lax
5 changes: 5 additions & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,8 @@ generate-docs:
.PHONY: add-known-sdk-version
add-known-sdk-version:
poetry run python scripts/add-known-sdk-version.py $(opts)

.PHONY: reset
reset: docker-up
poetry run python manage.py waitfordb
poetry run python manage.py reset_local_database
4 changes: 4 additions & 0 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,3 +1471,7 @@
PYLON_IDENTITY_VERIFICATION_SECRET = env.str("PYLON_IDENTITY_VERIFICATION_SECRET", None)

OSIC_UPDATE_BATCH_SIZE = env.int("OSIC_UPDATE_BATCH_SIZE", default=500)

# Allow the reset_local_database management command to run.
# This command flushes and seeds the database with test data.
ENABLE_LOCAL_DATABASE_RESET = False
2 changes: 2 additions & 0 deletions api/app/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
ENABLE_ADMIN_ACCESS_USER_PASS = True

SKIP_MIGRATION_TESTS = True

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing testserver in ALLOWED_HOSTS for local settings

The reset_local_database command uses Django REST Framework's APIClient which makes requests with Host: testserver (Django's default for test clients). However, local.py only adds ".ngrok.io", "127.0.0.1", and "localhost" to ALLOWED_HOSTS, not "testserver". Since DEBUG defaults to False in common.py and isn't overridden in .env-local or local.py, Django will validate the Host header and reject all APIClient requests with a DisallowedHost exception. The tests pass because test.py both sets DEBUG = True and adds "testserver" to ALLOWED_HOSTS, but running make reset with local settings will fail.

Fix in Cursor Fix in Web

ENABLE_LOCAL_DATABASE_RESET = True
4 changes: 3 additions & 1 deletion api/app/settings/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from app.settings.common import * # noqa
from app.settings.common import REST_FRAMEWORK
from app.settings.common import ALLOWED_HOSTS, REST_FRAMEWORK

ALLOWED_HOSTS = [*ALLOWED_HOSTS, "testserver"]

# We dont want to track tests
ENABLE_TELEMETRY = False
Expand Down
Loading
Loading