You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I copied* this example from FastAPI's docs, added testing using TestClient and logfire with logfire.instrument_pydantic(), and encountered an error. The app without the line logfire.instrument_pydantic() works fine.
(*I removed irrelevant routes).
sqlalchemy.exc.NoInspectionAvailable: No inspection system is available for object of type <class 'index.Hero'>
part of trace:
<...>
/home/igor/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py:807: in run
result = context.run(func, *args)
index.py:65: in create_hero
db_hero = Hero.model_validate(hero)
/home/igor/.local/lib/python3.10/site-packages/sqlmodel/main.py:848: in model_validate
return sqlmodel_validate(
/home/igor/.local/lib/python3.10/site-packages/sqlmodel/_compat.py:320: in sqlmodel_validate
cls.__pydantic_validator__.validate_python(
/home/igor/.local/lib/python3.10/site-packages/logfire/integrations/pydantic.py:139: in wrapped_validator
self._on_success(span, result)
/home/igor/.local/lib/python3.10/site-packages/logfire/integrations/pydantic.py:195: in _on_success
self._set_span_attributes(
<...>
/home/igor/.local/lib/python3.10/site-packages/logfire/_internal/main.py:2090: in set_attribute
self._json_schema_properties[key] = create_json_schema(value, set())
/home/igor/.local/lib/python3.10/site-packages/logfire/_internal/json_schema.py:149: in create_json_schema
log_internal_error()
/home/igor/.local/lib/python3.10/site-packages/logfire/_internal/json_schema.py:127: in create_json_schema
return _sqlalchemy_schema(obj, seen)
/home/igor/.local/lib/python3.10/site-packages/logfire/_internal/json_schema.py:344: in _sqlalchemy_schema
state = sa_inspect(obj)
I may be wrong, this is just my opinion, but it may be useful.
Logfire is trying to log the instance of <class 'index.Hero'> (which is successfully created) and attempts to create json from it: link to code line
is_sqlalchemy(obj) is Truebecause<class 'index.Hero'> is instance of DeclarativeMeta.
But _sqlalchemy_schema(obj, seen)does something called
forclsintype_.__mro__:
<...>
and mro is <class 'index.Hero'>, <class 'index.HeroBase'>, <class 'sqlmodel.main.SQLModel'>, <class 'pydantic.main.BaseModel'>, <class 'object'>. Maybe the SQLModel class is somehow "not connected" with sqlalchemy.inspect() and refuses to work properly, but I don't have enough knowledge about sqlalchemy, so I'm sorry for my (probably clueless) guesses.
Python, Logfire & OS Versions, related packages (not required)
logfire="2.11.0"platform="Linux-6.8.0-49-generic-x86_64-with-glibc2.35"python="3.10.12 (main, Nov 6 2024, 20:22:13) [GCC 11.4.0]"
[related_packages]
requests="2.32.3"pydantic="2.10.3"fastapi="0.115.6"protobuf="5.29.2"rich="13.9.4"tomli="2.2.1"executing="2.0.1"opentelemetry-api="1.29.0"opentelemetry-exporter-otlp-proto-common="1.29.0"opentelemetry-exporter-otlp-proto-http="1.29.0"opentelemetry-instrumentation="0.50b0"opentelemetry-instrumentation-asgi="0.50b0"opentelemetry-instrumentation-fastapi="0.50b0"opentelemetry-instrumentation-sqlalchemy="0.50b0"opentelemetry-proto="1.29.0"opentelemetry-sdk="1.29.0"opentelemetry-semantic-conventions="0.50b0"opentelemetry-util-http="0.50b0"
The text was updated successfully, but these errors were encountered:
Description
Summary
I copied* this example from FastAPI's docs, added testing using
TestClient
and logfire withlogfire.instrument_pydantic()
, and encountered an error. The app without the linelogfire.instrument_pydantic()
works fine.(*I removed irrelevant routes).
Details
Here is the
index.py
code:I ran
pytest index.py
and got the error:part of trace:
Full trace: pytest_output.txt
Possible reason
I may be wrong, this is just my opinion, but it may be useful.
Logfire is trying to log the instance of <class 'index.Hero'> (which is successfully created) and attempts to create json from it:
link to code line
is_sqlalchemy(obj)
isTrue
because<class 'index.Hero'>
is instance ofDeclarativeMeta
.But
_sqlalchemy_schema(obj, seen)
does something calledand mro is
<class 'index.Hero'>, <class 'index.HeroBase'>, <class 'sqlmodel.main.SQLModel'>, <class 'pydantic.main.BaseModel'>, <class 'object'>
. Maybe the SQLModel class is somehow "not connected" withsqlalchemy.inspect()
and refuses to work properly, but I don't have enough knowledge about sqlalchemy, so I'm sorry for my (probably clueless) guesses.Python, Logfire & OS Versions, related packages (not required)
The text was updated successfully, but these errors were encountered: