Carbon0-Games/carbon0-web-app

MixpanelException thrown on certain environments

Opened this issue · 0 comments

Hey folks,

The Problem
After merging PR #39 , @KitsuneNoctus noticed that a MixpanelException was being thrown on his local machine, whenever he ran the app locally, and activated a view function that had integrated Mixpanel functionality server-side.

Put another way, we're having issues with the mp.track function, when it is called in carbon0/carbon_quiz/views.py, on line number 47 (part of the track_achievement_creation function).

Solutions Tried So Far
This error was originally discovered on the HenryC branch. However that's the only place we've found it so far. When I deployed to Heroku, Mixpanel worked fine there; as well as when I ran the HenryC locally on my own machine, the events fired with no issue, and I was able to see them appear on the Mixpanel dashboard.

I am led to believe this might just be an issue with the environment setup on @KitsuneNoctus 's computer, and I am curious to see what the difference is so we can avoid this issue in the future.

For now, the temporary fix is to use a try-except statement in Python, using the MixpanelException provided by the mixpanel Python package, so that at least when the error occurs locally it won't break your server. What this means for right now: whenever you use the Mixpanel API server-side (aka on any of the Python files), use the following format:

# import Mixpanel classes
from mixpanel import Mixpanel, MixpanelException
# import the project token for Mixpanel
from django.conf import settings
...

# instantiate the Mixpanel object, using the Project token
mp = Mixpanel(settings.MP_PROJECT_TOKEN)

# use the Mixpanel functions, with a try statement
try:
     mp.something()
# catch the errors if any
except MixpanelException:
     # log the error happened on the Terminal if you want
     print('MixpanelException occurred!')

Please let us know if that pattern still breaks for you!

Resources
Mixpanel Python SDK docs

Additional Notes
The other functions that may be at risk are the others that use the Mixpanel SDK for Python, so we might want to monitor:

  1. track_successful_signup
  2. track_login_event

Both of these will be found in the carbon0/accounts/views.py file.