Giter Site home page Giter Site logo

Comments (10)

provinzkraut avatar provinzkraut commented on June 5, 2024

Okay so I think the issue here is that we don't respect the Config.underscore_attrs_are_private. IMO we simply shouldn't touch the underscore fields at all if this is set. @litestar-org/maintainers?

We actually do. This is a different issue.

from litestar.

provinzkraut avatar provinzkraut commented on June 5, 2024

Issue here is that while we do exclude those fields from the schema, we still try to extract their type annotations.

from litestar.

provinzkraut avatar provinzkraut commented on June 5, 2024

@mike0sv There's a fix in #3151. Can you give it a try and confirm that it solve the issue for you?

from litestar.

github-actions avatar github-actions commented on June 5, 2024

This issue has been closed in #3151. The change will be included in the upcoming patch release.

from litestar.

mike0sv avatar mike0sv commented on June 5, 2024

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()

from litestar.

provinzkraut avatar provinzkraut commented on June 5, 2024

This seems to be exclusive to Pydantic V1 though; I couldn't reproduce with V2.

from litestar.

provinzkraut avatar provinzkraut commented on June 5, 2024

@mike0sv I've created a follow-up here: #3161, which seems to fix your most recent MCVE as well. Let me know if this works for you.

from litestar.

github-actions avatar github-actions commented on June 5, 2024

This issue has been closed in #3161. The change will be included in the upcoming patch release.

from litestar.

mike0sv avatar mike0sv commented on June 5, 2024

Yes! Thanks!

from litestar.

github-actions avatar github-actions commented on June 5, 2024

A fix for this issue has been released in v2.6.3

from litestar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.