terça-feira, 13 de maio de 2025

Solution to "ImportError: cannot import name 'GrowthBookClient' from 'growthbook'"

If you're using version 1.2.1 of the GrowthBook Python library, you may have seen in the documentation on GitHub or PyPI that the GrowthBookClient should be imported like this:

from growthbook import GrowthBookClient

 However, this results in the following error:

api/feature_flag_service.py", line 1, in <module>

    from growthbook import GrowthBookClient, Options, UserContext

ImportError: cannot import name 'GrowthBookClient' from 'growthbook'

The fix is simple: instead of following the documentation, use the correct import path based on the actual library structure:

from growthbook.growthbook_client import GrowthBookClient 

quinta-feira, 1 de maio de 2025

Solution to sqlx prepare error: failed to lookup address information: Name or service not known

I was getting the error "failed to lookup address information: Name or service not known" when running the command cargo sqlx prepare. The error seemed obvious — my DATABASE_URL environment variable was probably incorrect. However, after checking everything and confirming that it was correct (ad-hoc connections were working, and even the service startup connected successfully), I figured out the issue:

My service required additional environment variables to start. Without these env vars, it wouldn't start and would return an error. It turns out that when running cargo sqlx prepare without those variables, the error gets silently swallowed, and the database connection simply fails.

After supplying the same environment variables I use for cargo run to cargo sqlx prepare, the problem was resolved.