Skip to content

Fix deprecated Posthog API Key initialization #91

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

Merged
merged 7 commits into from
Jul 21, 2025
Merged

Conversation

bryannho
Copy link
Contributor

@bryannho bryannho commented Jul 17, 2025

Describe your changes

  • CLI was throwing an error when making telemetry calls due to the Posthog key not being initialized
  • We can no longer set the posthog API key via posthog.project_api_key = self.api_key since its deprecated
  • Updated the initialization to posthog.Posthog(api_key, host='https://us.i.posthog.com') and changed the log_api function to use this client

Issue number

Fixes support issue: https://ploomber-io.slack.com/archives/C08QNPDF15J/p1752779413170409

Checklist before requesting a review


📚 Documentation preview 📚: https://ploomber-core--91.org.readthedocs.build/en/91/

@bryannho bryannho added the bug Something isn't working label Jul 17, 2025
Copy link
Contributor

@edublancas edublancas left a comment

Choose a reason for hiding this comment

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

let's look up in which posthog package version this was applied, and put it here:

core/setup.py

Line 18 in 3fdc748

"posthog",
like posthog>=x.y.z

also, the docs are failing because we're missing this: https://github.com/ploomber/jupysql/blob/6f83dbec7659124efe00c8ab1c3838b404fc0f3f/.readthedocs.yml#L24
image

the CI is also failing, I think because the Python versions are too old. let's only test with 3.10, 3.11 and 3.12

setup.py Outdated
@@ -15,7 +15,7 @@

REQUIRES = [
"pyyaml",
"posthog",
"posthog<3.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

the pin should be the other way around: >x.y.z

your previous changes were fine but we need to pin to ensure that the new version also forces a posthog upgrade

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pinned the version to >=3.0

@bryannho
Copy link
Contributor Author

@edublancas before I saw your review I went back and pinned the version instead of making the changes (since I saw the tests were failing due to PH not supporting python 3.8)

If you're okay with removing the python 3.8 tests then I'll bring back the original changes and apply your notes

@edublancas
Copy link
Contributor

im ok removing old python versions

@bryannho
Copy link
Contributor Author

Tests are failing due to failed mocks. Updating them now

@bryannho bryannho requested a review from edublancas July 17, 2025 22:37
@bryannho
Copy link
Contributor Author

@edublancas please review again when you get the chance

self._posthog_client = posthog.Posthog(
api_key, host="https://us.i.posthog.com"
)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't a good way to handle an incompatibilty, instead we can raise an error telling users they must upgrade posthog or downgrade ploomber-core

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed: ca6301a

@bryannho bryannho requested a review from edublancas July 21, 2025 16:32
@edublancas edublancas merged commit 88dee86 into main Jul 21, 2025
23 checks passed
@edublancas edublancas deleted the bryan/ph-api-key branch July 21, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants