-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: pydantic PrivateAttr fields are inspected for type hints #3150
Comments
We actually do. This is a different issue. |
Issue here is that while we do exclude those fields from the schema, we still try to extract their type annotations. |
This issue has been closed in #3151. The change will be included in the upcoming patch release. |
I tested it and it works for MCVE, but it still fails for evidently codebase. I narrowed it down to the fact that our "Model" class is actually a generic. Here is the new MCVE from typing import Generic, Optional, TYPE_CHECKING, TypeVar
from litestar import Litestar, post
from litestar._openapi.plugin import OpenAPIPlugin
from pydantic import BaseModel
if TYPE_CHECKING:
from typing import Any
T = TypeVar("T")
class Model(BaseModel, Generic[T]):
class Config:
underscore_attrs_are_private = True
_value: Optional["Any"]
@post("/")
def hello_world(data: Model) -> dict[str, str]:
"""Keeping the tradition alive with hello world."""
return {"hello": "world"}
def main():
app = Litestar(route_handlers=[hello_world], )
app.plugins.get(OpenAPIPlugin).provide_openapi()
if __name__ == '__main__':
main() |
This seems to be exclusive to Pydantic V1 though; I couldn't reproduce with V2. |
This issue has been closed in #3161. The change will be included in the upcoming patch release. |
Yes! Thanks! |
…tes (litestar-org#3150) (litestar-org#3151) * Fix OpenAPI schema generation for Pydantic v2 constrained secrets
A fix for this issue has been released in v2.6.3 |
- Schema generation fixed
* New trigger has been added to initiate a snapshot for the collector based on time or the number of rows * fix: Collector litestar server cant start #1012 * Implement repeated call of check_snapshots_factory using lifespan * Update linestar to 2.6.3 litestar-org/litestar#3150 - Schema generation fixed * Added error logging for snapshot creation * Added call of synchronous functions using ThreadPoolExecutor in create_snapshot to avoid blocking the loop * CollectorClient returns the response as a dict * Added smoke tests for the core functionality of the collector api * Update tests/collector/test_app.py Co-authored-by: Janek Nouvertné <[email protected]> * Skip server tests --------- Co-authored-by: Mikhail Sveshnikov <[email protected]> Co-authored-by: Janek Nouvertné <[email protected]>
Description
If a private field is annotated with unresolvable ForwardRef, openapi schema build fails (see example)
URL to code causing the issue
No response
MCVE
Steps to reproduce
Screenshots
Logs
Litestar Version
litestar==2.5.1
Platform
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: