Skip to content

Conversation

@clutchski
Copy link
Collaborator

@clutchski clutchski commented Feb 10, 2026

Summary

  • _ensure_model_wrapped None check (7c84b727): _ensure_model_wrapped() called type(instance._model) without checking for None, crashing with AttributeError: type object 'NoneType' has no attribute 'request' when an agent is created without a model parameter.
  • _is_patched MRO inheritance bug (be713f48): _is_patched() used getattr() which walks the MRO, so wrapping WrapperModel first caused InstrumentedModel to appear already-patched (it inherited the flag from its parent). This meant InstrumentedModel.request() was never wrapped and the inner "chat" span was lost when logfire co-instruments pydantic_ai.
  • Add a dedicated test_pydantic_ai_logfire nox session that installs both pydantic_ai and logfire to verify they coexist correctly.

Fixes #1324

Test plan

  • nox -s test_pydantic_ai_logfire passes (2 spans: agent_run + chat)
  • nox -s "test_pydantic_ai_integration(latest)" passes (50 tests + 369 core)
  • nox -s pylint passes

🤖 Generated with Claude Code

clutchski and others added 2 commits February 10, 2026 17:15
_is_patched() used getattr() which walks the MRO, so wrapping
WrapperModel first caused InstrumentedModel to appear already-patched
(inheriting the flag). This meant InstrumentedModel.request() was never
wrapped and the inner "chat" span was lost when logfire co-instruments.

Fix by checking __dict__ directly for class objects. Add a dedicated
test_pydantic_ai_logfire nox session that installs both pydantic_ai and
logfire to verify they coexist correctly (issue #1324).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@clutchski clutchski changed the title Ensure pydantic handles "model" less agents. Fix _is_patched MRO bug losing chat spans with logfire Feb 11, 2026
@clutchski clutchski changed the title Fix _is_patched MRO bug losing chat spans with logfire pydantic patching fixes Feb 11, 2026
@clutchski clutchski marked this pull request as ready for review February 11, 2026 03:34
@clutchski clutchski requested a review from ibolmo February 11, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Braintrust setup_pydantic_ai() conflicts with Logfire instrumentation

1 participant