Thanks to visit codestin.com
Credit goes to github.com

Skip to content

🌐 Add Chinese translation for docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md#3494

Closed
jaystone776 wants to merge 4 commits into
fastapi:masterfrom
jaystone776:Add-Chinese-translation-for-tutorial-dependencies-dependencies-with-yield.md
Closed

🌐 Add Chinese translation for docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md#3494
jaystone776 wants to merge 4 commits into
fastapi:masterfrom
jaystone776:Add-Chinese-translation-for-tutorial-dependencies-dependencies-with-yield.md

Conversation

@jaystone776

Copy link
Copy Markdown
Contributor

…ield.md

as title

@codecov

codecov Bot commented Jul 7, 2021

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cf73051) 100.00% compared to head (fba3fb5) 100.00%.
Report is 1086 commits behind head on master.

❗ Current head fba3fb5 differs from pull request most recent head 979ade8. Consider uploading reports for the commit 979ade8 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #3494     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files          540       254    -286     
  Lines        13969      7860   -6109     
===========================================
- Hits         13969      7860   -6109     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Jul 7, 2021

Copy link
Copy Markdown
Contributor

📝 Docs preview for commit fba3fb5 at: https://60e57a08e48305314659b399--fastapi.netlify.app

@waynerv waynerv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent works!


把依赖项的 `yield` 置于 `try` 代码块中,就可以接收到所有使用该依赖项时触发的异常。

假设执行过程中的某行代码(这行代码可能在*路径操作或其他依赖项中*)导致了数据库事务的「回滚」,或导致了任何其他错误,使用 `try` 就可以在当前依赖项中触发异常。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
假设执行过程中的某行代码(这行代码可能在*路径操作或其他依赖项中*)导致了数据库事务的「回滚」,或导致了任何其他错误,使用 `try` 就可以在当前依赖项中触发异常。
假设执行过程中的某行代码(这行代码可能在*路径操作或其他依赖项中*)导致了数据库事务的「回滚」,或导致了任何其他错误,使用 `try` 就可以在当前依赖项中触发异常。


通过这种方式,**FastAPI** 允许依赖项中的任意对象(例如,数据库会话)都可以用于后台任务。

后台任务是在响应发送*后*执行的任务。所以,此时抛出 HTTPException 没有意义,因为没有办法改变*已发送*的响应。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
后台任务是在响应发送**执行的任务。所以,此时抛出 HTTPException 没有意义,因为没有办法改变*已发送*的响应。
后台任务是在响应发送**执行的任务。所以,此时抛出 HTTPException 没有意义,因为没有办法改变*已发送*的响应。


!!! tip "提示"

不要在 `yield` 语句之后,而是要在该语句之前触发 `HTTPException` 等异常。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
不要在 `yield` 语句之后,而是要在该语句之前触发 `HTTPException` 等异常
在依赖项的 `yield` 语句之前抛出 `HTTPException` 等异常仍然是可行的,但不能在 `yield` 之后

@tiangolo tiangolo changed the title Add Chinese translation for tutorial-dependencies dependencies-with-y… 🌐 Add Chinese translation for docs/tutorial/dependencies/dependencies-with-yield.md Jul 19, 2021
@tiangolo tiangolo added awaiting-review lang-all Translations lang-zh Chinese translations labels Jul 19, 2021
jaystone776 and others added 2 commits September 1, 2021 13:38
change 其他 to 其它
change 开发人员 to 开发者
change 「」 to bold for better reading experience
@tiangolo

Copy link
Copy Markdown
Member

📝 Docs preview for commit 979ade8 at: https://6499d1a2bac8cd0a1954b002--fastapi.netlify.app

@alejsdev alejsdev changed the title 🌐 Add Chinese translation for docs/tutorial/dependencies/dependencies-with-yield.md 🌐 Add Chinese translation for docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md Jan 29, 2024
@alejsdev

alejsdev commented Feb 1, 2024

Copy link
Copy Markdown
Member

Hi! This one was already handled in #10870. For now, I'll close this one, but thanks for the help @jaystone776 @waynerv 🚀

@alejsdev alejsdev closed this Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved-1 lang-all Translations lang-zh Chinese translations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants