FrankWiles.com

TIL: Today I Learned

httpx and Orbstack compatability issue

So I updated Orbstack today to the latest version Version 2.1.2 (20103). I’m a big Orbstack fan and this is the first time in a LONG time that it caused me any pain at all.

And this was a pretty small pain. Claude and I were able to figure out a solution quickly.

The Symptom

After updating Orbstack I re-ran a large suite of pytest tests on a Django project. This project uses httpx to hit some third party APIs directly.
We do need to support HTTP proxying as in a couple of scenarios we need to proxy via a Tailscale service for unimportant reasons.

We started getting errors that included:

httpx.InvalidURL: Invalid port: 'b51a:cc66:f0::'

I think is somehow related to a feature change or bugfix related to special *.orb.local domain that Orbstack sets up for you, but I do not for various reasons, use myself.

The Fix

We already had an autoused pytest fixture that changes some of our Django settings while testing. This settings fixture is provided by the lovely pytest-django project if you haven’t seen it used before.

@pytest.fixture(autouse=True)
def use_test_settings(settings, monkeypatch):
    # httpx 0.28+ fails to parse IPv6 CIDR entries 
    # (e.g. fd07:b51a:cc66:f0::/64) in NO_PROXY, 
    # which OrbStack sets. Clear all proxy env 
    # vars for tests.
    for _proxy_var in ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY",
                       "http_proxy", "https_proxy", "all_proxy", "no_proxy"]:
        monkeypatch.delenv(_proxy_var, raising=False)

    # Continue with other Django settings 
     settings.CACHES = {
         "default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}
     }

So the fix is we need to strip out these proxy env vars and then everything goes back to passing.

Hope this helps you get around it faster if you too run into this situation.

RSS Feed All Content | RSS Feed All TIL