Skip to content
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

Fix/depricated refrence in sql databases #13253

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

IdleSys
Copy link

@IdleSys IdleSys commented Jan 24, 2025

Overview

This pull request updates the FastAPI documentation to reflect the deprecation of the @app.on_event decorator in the SQL database section of tutorial. The documentation has been revised to guide users towards using the new lifespan event handling system for managing application startup and shutdown events.

Changes Made

Updated Documentation:

  • Removed references to @app.on_event in python doc_src files.
  • Code demonstration updated in documentation markdown files for English.

Testing

  • Reviewed all modified documentation for accuracy and clarity.
  • Ensured that all examples are functional and correctly illustrate the new usage patterns.

@github-actions github-actions bot added the docs Documentation about how to use FastAPI label Jan 24, 2025
Copy link
Contributor

Copy link
Contributor


### Create Database Tables on Startup

We will create the database tables when the application starts.

{* ../../docs_src/sql_databases/tutorial001_an_py310.py ln[32:37] hl[35:37] *}
{* ../../docs_src/sql_databases/tutorial001_an_py310.py ln[33:40] hl[33:36, 40] *}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to include into this part of the code the line:

app = FastAPI(lifespan=lifespan)

So that the full lifespan integration process is shown.

Copy link
Author

@IdleSys IdleSys Jan 25, 2025

Choose a reason for hiding this comment

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

I'm pretty sure it was included. as you can see i highlighted a blank line.... I think it must be due to the pre-commit format or my fork not being synced with master.
I'll check it.

@alv2017
Copy link
Contributor

alv2017 commented Jan 25, 2025

I support the changes proposed by @IdleSys. 👍

The corrections I suggested are optional, and it is up to the PR author to implement them or not. 😊

Copy link
Contributor

@IdleSys IdleSys force-pushed the fix/depricatedRefrenceInSqlDatabases branch from 3afe545 to 2f95f2b Compare January 25, 2025 16:43
Copy link
Contributor

@alv2017
Copy link
Contributor

alv2017 commented Jan 25, 2025

There is one more thing to think about: when the reference code is modified all the translations related to it will get corrupted.

@IdleSys
Copy link
Author

IdleSys commented Jan 25, 2025

Thank you for your input, @alv2017

Currently, I am facing an issue where my local preview does not match the preview of the link that robot provided. Regarding the problem you mentioned, it arises from my changes to the document sources. I see two possible solutions:

  • Separate the sources until the translations are updated to align with the new source. This approach would also retain the deprecated statements for translations.
  • Sync the translations with the new source, although I doubt my time and interest will allow me to pursue this option.

@alv2017
Copy link
Contributor

alv2017 commented Jan 25, 2025

  1. I reviewed updated code references, everything looks good now.

  2. In the mean time I found out that there are not that many translations of the sql-databases.md:

  • es
  • ko
  • pt
  • ru
  • zn

all the groups are quite active, and probably it won't be difficult to get support from them

  1. There is an alternative solution. The source files related to the tutorials have a special structure:
    If we create a file named tutorial001_py311_an.py and apply all the necessary changes there, and then link it to the english version of the tutorial, then translations won't be affected.

I think that we will need help from the maintainers to move forwards with that.

@IdleSys
Copy link
Author

IdleSys commented Jan 26, 2025

@alv2017 Good News
I successfully navigated through the Spanish version and updated all occurrences of old references using sed and I would appreciate it if someone from another language team could visually check and confirm the changes.

Copy link
Contributor

@alv2017 alv2017 left a comment

Choose a reason for hiding this comment

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

Do not rush. 😄 :
I approve your proposal regarding documentation update, but the pull request doesn't look good to me, it just got too complicated. I doubt that it can be approved.

It is time to ask for guidance and advice. 😊


### Create Database Tables on Startup

We will create the database tables when the application starts.

{* ../../docs_src/sql_databases/tutorial001_an_py310.py ln[32:37] hl[35:37] *}
{* ../../docs_src/sql_databases/tutorial001_an_py310.py ln[33:40] hl[33:36, 40] *}

Here we create the tables on an application startup event.
Copy link
Contributor

Choose a reason for hiding this comment

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

In this place I suggest to explain that with the help of the lifespan we create the tables before the application starts accepting requests, and provide the link to the Lifespan tutorial.

So that we get rid of warning, that introduce extra complication to the content.

Comment on lines +112 to +121

/// warning

The `@app.on_event("startup")` and `@app.on_event("shutdown")` decorators are **deprecated** as of FastAPI v0.103.0.

Use the <a href="https://fastapi.tiangolo.com/advanced/events/#lifespan" class="external-link" target="_blank">`lifespan`</a> parameter in the `FastAPI` class instead for lifecycle management.

///


Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to get rid of the warning, and explain the usage of the lifespan in the sentence that I commented above.

@alv2017
Copy link
Contributor

alv2017 commented Jan 26, 2025

Hi @tiangolo, @alejsdev, sorry for bothering you, but we need your help and guidance.

We would like to make some updates to the code related to the SQL (Relational) Databases tutorial, and guide users towards using the new lifespan event handling system for managing application startup and shutdown events.

However when working on the PR we noticed, that it gets overly complex.
The PR in its current state demonstrates the scope of work that needs to be done in order to introduce the change.

The required changes are as follows:

  1. Code updates
  2. English documentation update
  3. The update of existing translations (mainly code references): At the moment the following translations are available: es, ko, pt, ru, zh

Questions:

  1. Do you agree with this change in documentation?
  2. If yes, then we will be happy to help, but we need your guidance and advice on making the PR.

Thank you! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants