Skip to content
Discussion options

You must be logged in to vote

Since you specify Depends(get_current_user), current_user will always get the value returned by get_current_user() when get_posts() is called by FastAPI. Therefore, setting the default value with = None will have no effect within FastAPI.

The only case it will have an effect is if you call get_posts() directly in some other code. In that case, if you don't pass a value for current_user, Python will apply the default. Note that this is an uncommon case, since usually only FastAPI calls your handlers and you don't call them yourself as normal functions.

Also as a side note, this is most likely also a type error, unless User is some union type that allows None as a value.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ezeparziale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants