Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

♻️ Ignore on_event is deprecated deprecation warnings, fix ValidationError import warning #1600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
YuriiMotov wants to merge 2 commits into fastapi:main
base: main
Choose a base branch
Loading
from YuriiMotov:suppress_known_warnings_in_tests

Conversation

@YuriiMotov
Copy link
Member

@YuriiMotov YuriiMotov commented Oct 9, 2025
edited
Loading

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
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

Reviewers

@svlandeg svlandeg svlandeg left review comments

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /