Replies: 18 comments 1 reply
-
I am getting a similar problem. Am getting the following errors.
Upon further inspection of the code with the following lines: flat_models = get_flat_models_from_routes(routes)
model_name_map = get_model_name_map(flat_models)
definitions = get_model_definitions(
flat_models=flat_models, model_name_map=model_name_map
) The problem is that basically that in my case, the variables passed into So the problem in my case is that Once I remove code with my auth endpoints, openapi schema gets generated and docs do not crash, but I get many instances of the following errors.
My repo with the following problem is referenced above. |
Beta Was this translation helpful? Give feedback.
-
Nevermind, found a solution. For future reference, the commit above fixed the issue. I was transferring some code from another project. Sorry if maybe not exactly relevant to the issue, but hope it helps someone in the future. |
Beta Was this translation helpful? Give feedback.
-
@bruchar1 this solution above solve yout problem? |
Beta Was this translation helpful? Give feedback.
-
No. @mbrav problem is unrelated to this. |
Beta Was this translation helpful? Give feedback.
-
@mbrav I believe this issue can be closed then :) |
Beta Was this translation helpful? Give feedback.
-
@jonatasoli I agree, but I am not the one who opened it :) |
Beta Was this translation helpful? Give feedback.
-
@jonatasoli Why do you want to close this? The bug is still there, and completely unrelated to @mbrav issue. |
Beta Was this translation helpful? Give feedback.
-
There are multiple issues here:
I'll create a quick MR to change the btw my current workaround is just splitting up the routes to different functions, so using |
Beta Was this translation helpful? Give feedback.
-
Hello @bneijt, I confirm I hit the same issue with [email protected]. I've decorated a method like this: @router.api_route(
"/example",
methods=["POST", "PUT"],
status_code=status.HTTP_201_CREATED,
)
async def save_example(...)
pass |
Beta Was this translation helpful? Give feedback.
-
health_system.pyrouter = APIRouter(prefix="/system", route_class=ContextLogerRoute) @router.get('/health', tags=['默认开启的健康检查']) ================ =================== How to solve this problem? |
Beta Was this translation helpful? Give feedback.
-
@462548187 I suppose the warning comes from the /system route. You need to specify a particular method (a.k.a HTTP request method type). It has to work with the warning though. |
Beta Was this translation helpful? Give feedback.
-
Similar problem :
|
Beta Was this translation helpful? Give feedback.
-
Similar issue: UserWarning: Duplicate Operation IDI've been reducing my example until all I have is this: Freezefastapi==0.88.0
|
Beta Was this translation helpful? Give feedback.
-
@ricardo-reis-1970 do you get these warnings only when running tests or also when running the app itself? Because for me it's only when running pytest. I haven't session-scoped my |
Beta Was this translation helpful? Give feedback.
-
Just a thought: Can you or anyone facing the issue, confirm if you have included the router (with all routes) only once in the parent router or the fastapi app? |
Beta Was this translation helpful? Give feedback.
-
@KRC1997 Yeah you're right (in a way). I only add the router once, but the problem occurred when I started using asgi-lifespan to include the startup- and shutdown routines (the app lifecycle) of my app when running tests. I had my The following workaround fixed the problem for me and also fixed another issue I had anyway: I now still initialize the database client in the startup routine (and close it in the shutdown routine) but everything that belongs to initializing the actual app instance (e.g. registering routers), I moved to a def pre_startup_routine(app: FastAPI) -> None:
# add middlewares
...
# register routers
...
async def startup_routine() -> None:
# init database client
...
async def shutdown_routine() -> None:
# close database client and cleanup
...
# create FastAPI app instance
app = FastAPI(
# ...
on_startup=[startup_routine],
on_shutdown=[shutdown_routine],
)
pre_startup_routine(app) This has the additional advantage that it works well with my test setup. |
Beta Was this translation helpful? Give feedback.
-
@bkis yeah, i do believe it has something to do with the lifecycle of the |
Beta Was this translation helpful? Give feedback.
-
I submitted a PR that solves this issue: #10694 The duplication of operation ID happens because the The correct approach would be to refactor this functionality but then it might lead to backward incompatibility... the proposed workaround will add the correct method suffix only when there are more than one method on the same function. Example: @app.api_route("/multiple-methods", methods=["GET", "POST"])
def multiple_methods():
return {"message": "Hello World"} The proposed solution will generate 2 unique IDs (as expected):
instead of generating |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
Seems to be caused by #4650.
The new
generate_unique_id()
function useslist(route.methods)[0].lower()
as suffix for theoperation_id
. Therefore, in my example, both post and delete endpoints get_post
suffix for operation_id, causing it to no longer be unique.It then issues a "UserWarning: Duplicate Operation ID"
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.75.0
Python Version
3.10.2
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions