Create a user programmatically documentation - change example to return things. (#1356)

* Changed method to return user or raise an exception

* Re-raise UserAlreadyExists exception instead of creating a new one.
This commit is contained in:
Mark Donnelly
2024-02-20 00:42:23 -07:00
committed by GitHub
parent 3e38e1154c
commit d6e337a2e5
2 changed files with 3 additions and 1 deletions

View File

@ -30,7 +30,7 @@ In the following sample, we import our dependencies and create a context manager
We are now ready to write a function. The example below shows you a basic example but you can of course adapt it to your own needs. The key part here is once again to **take care of opening every context managers and pass them every required arguments**, as the dependency manager would do.
```py hl_lines="13-25"
```py hl_lines="13-27"
--8<-- "docs/src/cookbook_create_user_programmatically.py"
```

View File

@ -21,5 +21,7 @@ async def create_user(email: str, password: str, is_superuser: bool = False):
)
)
print(f"User created {user}")
return user
except UserAlreadyExists:
print(f"User {email} already exists")
raise