Skip to content

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

@PeterStolz

Description

@PeterStolz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions