Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posthog.project_api_key should be able to be None if (posthog.disabled == True) #173

Open
PeterStolz opened this issue Jan 23, 2025 · 0 comments

Comments

@PeterStolz
Copy link

Hi,
I recently integrated posthog into our backend and I do not like that a posthog.capture can crash if the api key is not set even when I set posthog.disabled = True.

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    posthog.capture("test", event="asd")
  File "venv/lib/python3.12/site-packages/posthog/__init__.py", line 67, in capture
    return _proxy(
           ^^^^^^^
  File "venv/lib/python3.12/site-packages/posthog/__init__.py", line 497, in _proxy
    default_client = Client(
                     ^^^^^^^
  File "venv/lib/python3.12/site-packages/posthog/client.py", line 69, in __init__
    require("api_key", self.api_key, string_types)
  File "venv/lib/python3.12/site-packages/posthog/client.py", line 941, in require
    raise AssertionError(msg)
AssertionError: api_key must have (<class 'str'>,), got: None

To me this feels like a bug.
You can reproduce with

import posthog

posthog.disabled = True
posthog.host = "https://eu.i.posthog.com"
posthog.capture("test", event="asd")

It happens on posthog==3.8.4 and posthog==3.9.3
If you agree that this should not be default behavior when posthog.disabled is set to True I can create a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant