Skip to content

🐛 Fix non-deterministic openapi spec in case of duplicated model names#14797

Closed
igoyak wants to merge 2 commits intofastapi:masterfrom
igoyak:fix-nondeterministic-openapi
Closed

🐛 Fix non-deterministic openapi spec in case of duplicated model names#14797
igoyak wants to merge 2 commits intofastapi:masterfrom
igoyak:fix-nondeterministic-openapi

Conversation

@igoyak
Copy link
Copy Markdown

@igoyak igoyak commented Feb 1, 2026

v0.128.0 introduced non-deterministic openapi spec schema naming in the case of multiple pydantic models with the same name.

Commit e300630 removed the check for conflicting names.

The component names two classes named User would randomly be either

User
tests__test_duplicate_model_names_openapi__b__model__User
tests__test_duplicate_model_names_openapi__a__model__User
User

With this change, we reintroduce the conflict check to always use fully qualified names in case of conflict.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 1, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing igoyak:fix-nondeterministic-openapi (a77a07b) with master (bc9ad6b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (82959de) during the generation of this report, so bc9ad6b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@igoyak igoyak force-pushed the fix-nondeterministic-openapi branch 4 times, most recently from 90a6bb7 to 4412526 Compare February 1, 2026 14:29
@igoyak igoyak marked this pull request as ready for review February 1, 2026 14:56
Copy link
Copy Markdown
Member

@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

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

@igoyak, thanks for your interest and efforts!

I think we should think if we can avoid exposing the path of the module.
I can see the following approaches:

  • In case of name ambiguity, generate names this way (with module path), but issue a warning. So that developers could notice it and prevent the leakage of the internal implementation
  • Use the hash of module path instead of path itself (still not very secure)
  • Use one of methods above, but provide the way to override the way unique components names are created (similar to generate_unique_id_function parameter)

@igoyak, what do you think?

Comment thread fastapi/_compat/v2.py Outdated
@YuriiMotov YuriiMotov added waiting bug Something isn't working labels Feb 2, 2026
@igoyak igoyak force-pushed the fix-nondeterministic-openapi branch 2 times, most recently from 8562605 to fb50eda Compare February 2, 2026 15:02
v0.128.0 introduced non-deterministic openapi spec schema naming in
the case of multiple pydantic models with the same name.

Commit [e300630](fastapi@e300630#diff-1086603fdd56511aafd1d279396b142b803e48164327148e6de26cef4cdaed81L504)
removed the check for conflicting names.

The component names two classes named `User` would randomly be either

```
User
tests__test_duplicate_model_names_openapi__b__model__User
```

```
tests__test_duplicate_model_names_openapi__a__model__User
User
```

With this change, we reintroduce the conflict check to always use
a hash of the fully qualified names in case of conflict.
@igoyak igoyak force-pushed the fix-nondeterministic-openapi branch from fb50eda to 748840e Compare February 2, 2026 15:18
@YuriiMotov
Copy link
Copy Markdown
Member

@igoyak, thanks!

Let's wait for Sebastian to review it and validate the idea.

I still think that we should emit a warning and provide a way for developers to override the function that is used for component names generation

@github-actions github-actions Bot removed the waiting label Feb 3, 2026
@YuriiMotov YuriiMotov changed the title Fix non-deterministic openapi spec 🐛 Fix non-deterministic openapi spec in case of duplicated model names Feb 3, 2026
@igoyak
Copy link
Copy Markdown
Author

igoyak commented Mar 26, 2026

Looks like this bugfix was essentially done (accidentally?) in cf55bad so closing this.

@igoyak igoyak closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants