What Python Errors Bugstack Fixes
- AttributeError: 'NoneType' object has no attribute — accessing attributes on None return values
- KeyError — accessing missing dictionary keys without .get()
- ImportError / ModuleNotFoundError — an import that fails while handling a request
- TypeError: argument of type 'NoneType' — passing None where a value is expected
- ValueError — invalid function arguments and type conversions
- Django ORM errors — DoesNotExist, MultipleObjectsReturned, field lookup failures
Install the SDK
Install the SDK:
pip install bugstack
Then initialize it with your API key and the Bugstack endpoint, and add the middleware. For FastAPI:
# In your main app file, after the FastAPI app is created:
import os
import bugstack
from bugstack.integrations.fastapi import FastAPIMiddleware
bugstack.init(
api_key=os.environ.get("BUGSTACK_API_KEY", ""),
endpoint=os.environ.get("BUGSTACK_ENDPOINT", "https://dashboard.bugstack.ai/api/ingest/sdk"),
)
app.add_middleware(FastAPIMiddleware)
Flask, Django and plain Python are in the installation guide.
Example Fix
Bugstack detects an AttributeError caused by calling a method on a None return value and writes a small fix:
Before (broken)
def get_user_email(user_id):
user = db.session.get(User, user_id)
return user.email
# Runtime error when user is None:
# AttributeError: 'NoneType' object
# has no attribute 'email'
After (fixed by Bugstack)
def get_user_email(user_id):
user = db.session.get(User, user_id)
if user is None:
return None
return user.email
Proven before you see it
Bugstack does not send this fix on trust. In an isolated copy of your repository, with the network cut, it writes a test that reproduces the crash and runs it with pytest on your current code: it fails with the same AttributeError. With the fix the test passes, and the rest of your suite still passes. Only then does the pull request open, with the test and that proof in it.
The reproduction test, shipped in the pull request
def test_get_user_email_unknown_user():
# Before the fix: AttributeError: 'NoneType' object
# has no attribute 'email'
assert get_user_email(user_id=999999) is None
See how the verification sandbox works.
What else Bugstack does for this repository
The SDK is one part. Once your repository is connected, Bugstack also scans your PyPI packages for known vulnerabilities and outdated versions, scans for secrets, and acts on failed deploys if you host on Render. It scans and reports, and it can open pull requests for what it finds. Those pull requests are switched on per account. Every change arrives as a pull request, and you set how much happens without you.