Skip to content

Conversation

YuriiMotov
Copy link
Member

@YuriiMotov YuriiMotov commented Oct 9, 2025

Currently we have a lot of deprecation warnings because we use fastapi.on_event in docs examples.
These warnings are useless and make it hard to read log of tests.
I suggest we just ignore "on_event is deprecated" warnings globally.

I also fixed import of ValidationError which also produced a deprecation warning.

With Pydantic V2 we still have 1 type of warnings:

SAWarning: Object of type <HeroTeamLink> not in session, add operation along 'Hero.team_links' will not proceed (This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation. Consider using ``no_autoflush`` context manager if this warning happened while initializing objects.)

Not sure how to fix this one..

See log
tests/test_tutorial/test_many_to_many/test_tutorial003.py::test_tutorial
tests/test_tutorial/test_many_to_many/test_tutorial003_py310.py::test_tutorial
tests/test_tutorial/test_many_to_many/test_tutorial003_py39.py::test_tutorial
  /home/yurii/code/sqlmodel_forks/motov/sqlmodel/sqlmodel/orm/session.py:144: SAWarning: Object of type <HeroTeamLink> not in session, add operation along 'Hero.team_links' will not proceed (This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation. Consider using ``no_autoflush`` context manager if this warning happened while initializing objects.)
    return super().execute(

tests/test_tutorial/test_many_to_many/test_tutorial003.py::test_tutorial
tests/test_tutorial/test_many_to_many/test_tutorial003_py310.py::test_tutorial
tests/test_tutorial/test_many_to_many/test_tutorial003_py39.py::test_tutorial
  /home/yurii/code/sqlmodel_forks/motov/sqlmodel/sqlmodel/orm/session.py:144: SAWarning: Object of type <HeroTeamLink> not in session, add operation along 'Team.hero_links' will not proceed (This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation. Consider using ``no_autoflush`` context manager if this warning happened while initializing objects.)
    return super().execute(

With Pydantic V1 we still have a lot of warnings, but they are not easily fixable.
Anyway, with this PR we will have less warnings and it will be easier to review test logs

Copy link
Contributor

github-actions bot commented Oct 9, 2025

📝 Docs preview

Last commit 7c8a330 at: https://4709c771.sqlmodel.pages.dev

@YuriiMotov YuriiMotov marked this pull request as ready for review October 9, 2025 21:30
@svlandeg svlandeg self-assigned this Oct 21, 2025
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I've forgotten/missed some previous discussion about this, but why don't we update the usage of on_event, e.g. like #958 attempts to do?

@svlandeg svlandeg removed their assignment Oct 21, 2025
@YuriiMotov
Copy link
Member Author

Maybe I've forgotten/missed some previous discussion about this, but why don't we update the usage of on_event, e.g. like #958 attempts to do?

#958 uses blocking function inside async lifespan function. That's not a good practice..

@asynccontextmanager
async def lifespan(app: FastAPI):
    create_db_and_tables()
    yield

We can update it to run it in the threadpool, but it will make the code example more complicated..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants