Skip to content

Commit

Permalink
Move get_self_capture_api_token inside of try, catch
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Jan 20, 2025
1 parent 63e25d9 commit 6364cf1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
3 changes: 0 additions & 3 deletions bin/migrate
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -e

SCRIPT_DIR=$(dirname "$(readlink -f "$0")")

export POSTHOG_RUNNING_MIGRATION=true
# NOTE when running in docker, rust might not exist so we need to check for it
if [ -d "$SCRIPT_DIR/../rust" ]; then
bash $SCRIPT_DIR/../rust/bin/migrate-cyclotron
Expand All @@ -27,5 +26,3 @@ python manage.py run_async_migrations --complete-noop-migrations
python manage.py run_async_migrations --check

wait $(jobs -p) # Make sure CH migrations are done before we exit

unset POSTHOG_RUNNING_MIGRATION
23 changes: 11 additions & 12 deletions posthog/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,18 @@ def ready(self):
{"git_rev": get_git_commit_short(), "git_branch": get_git_branch()},
)

if not os.getenv("POSTHOG_RUNNING_MIGRATION"):
try:
user = User.objects.filter(last_login__isnull=False).order_by("-last_login").first()
except:
user = None

try:
user = User.objects.filter(last_login__isnull=False).order_by("-last_login").first()
local_api_key = get_self_capture_api_token(user)

if SELF_CAPTURE and local_api_key:
posthoganalytics.api_key = local_api_key
posthoganalytics.host = settings.SITE_URL
else:
posthoganalytics.disabled = True
except:
user = None
local_api_key = None

if SELF_CAPTURE and local_api_key:
posthoganalytics.api_key = local_api_key
posthoganalytics.host = settings.SITE_URL
else:
posthoganalytics.disabled = True

# load feature flag definitions if not already loaded
if not posthoganalytics.disabled and posthoganalytics.feature_flag_definitions() is None:
Expand Down

0 comments on commit 6364cf1

Please sign in to comment.