Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 2 of 2 for get_database (0.18 sec)

  1. tests/test_dependency_normal_exceptions.py

    @app.put("/invalid-user/{user_id}")
    def put_invalid_user(
        user_id: str, name: str = Body(), db: dict = Depends(get_database)
    ):
        db[user_id] = name
        raise HTTPException(status_code=400, detail="Invalid user")
    
    
    @app.put("/user/{user_id}")
    def put_user(user_id: str, name: str = Body(), db: dict = Depends(get_database)):
        db[user_id] = name
        return {"message": "OK"}
    
    
    @pytest.fixture(autouse=True)
    Python
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sat Feb 24 23:06:37 GMT 2024
    - 1.9K bytes
    - Viewed (0)
  2. docs/en/docs/release-notes.md

    Dependencies with `yield` can now catch `HTTPException` and custom exceptions. For example:
    
    ```Python
    async def get_database():
        with Session() as session:
            try:
                yield session
            except HTTPException:
                session.rollback()
                raise
            finally:
    Plain Text
    - Registered: Sun Apr 28 07:19:10 GMT 2024
    - Last Modified: Sun Apr 28 00:28:00 GMT 2024
    - 385.5K bytes
    - Viewed (1)
Back to top