Comments (5)
So, the issue is with how dependencies are resolved. For money duplicate keys should be handled by at least deduplication, but perhaps also exception throwing during startup.
How about: deduplication if both key and value are identical. Otherwise, on key collision, raise an exception with a meaningful message?
from litestar.
So the issue is caused by the way that I'm using the dependencies in the example app.
class AbstractBaseRepository(ABC, Generic[DbType, ReturnType]):
def __init__(
self,
limit_offset: LimitOffset | None = None,
updated_filter: BeforeAfter | None = None,
) -> None:
...
I have a User repository:
class UserRepository(AbstractBaseRepository[User, UserModel]):
db_model = User
return_model = UserModel
And an Items repository which has specific methods that operate on a specific user items.
class ItemRepository(AbstractBaseRepository[Item, ItemModel]):
db_model = Item
return_model = ItemModel
async def get_many_for_user(
self, user: UserModel, **kwargs: Any
) -> list[ItemModel]:
...
The key thing is that the ItemRepository
methods require a UserModel
in their arguments.
So I include the UserRepository
and the ItemRepository
in the dependencies in the {user_id}/items
controller:
async def get_user(user_id: UUID, user_repository: UserRepository) -> UserModel:
return await user_repository.get_one(user_id)
router_dependencies = {
"repository": Provide(ItemRepository),
"user_repository": Provide(UserRepository),
"user": Provide(get_user),
}
... and that causes it to duplicate the query params in the schema.
from litestar.
This is the MCVE
def test_dependency_schema_generation_for_nested_routes() -> None:
class BaseDep:
def __init__(self, query_param: str) -> None:
...
class ADep(BaseDep):
...
class BDep(BaseDep):
...
@get("/test", dependencies={"a": Provide(ADep), "b": Provide(BDep)})
def handler(a: int, b: int) -> str:
return "OK"
app = Starlite(route_handlers=[handler], openapi_config=DEFAULT_OPENAPI_CONFIG)
open_api_path_item = app.openapi_schema.paths["/test"]
open_api_parameters = open_api_path_item.get.parameters
assert len(open_api_parameters) == 1 # fails with 2
from litestar.
This is a clearer example than the one above, just putting it here for clarity.
def c_dep(other_param: float) -> float:
...
def d_dep(other_param: float) -> float:
...
@get("/test", dependencies={"c": Provide(c_dep), "d": Provide(d_dep)})
def handler(c: float, d: float) -> str:
return "OK"
app = Starlite(route_handlers=[handler], openapi_config=DEFAULT_OPENAPI_CONFIG)
open_api_path_item = app.openapi_schema.paths["/test"]
open_api_parameters = open_api_path_item.get.parameters
assert len(open_api_parameters) == 1
So, where multiple dependencies of the route declare a parameter of the same name.
from litestar.
Closed in #129
from litestar.
Related Issues (20)
- bug: Plugin "Flash Messages" not working with "Redirect" Response HOT 4
- Bug: App launching fails because of Pydantic version handling problem HOT 4
- Bug: In 2.8.0, openapi triggers an ImproperlyConfiguredException HOT 9
- Enhancement: Serve openapi routes under multiple path prefixes HOT 3
- Bug: cannot start server with `PydanticPlugin` if using `pydantic == 1.x.x` HOT 2
- Bug: DTO doesn't work with Generic tuples
- Documentation: Consider depth of introductory State usage document
- Bug: pydantic version logic breaks with latest pydantic HOT 2
- Bug: Remove use of `assert` for pydantic import flow control HOT 3
- Docs: Update `usage/security/guards` chapter HOT 4
- Docs: Move `.. code-block::` directives into `docs/examples/`
- Bug: OpenAPI Specs incorrect for Paginated DTO Response HOT 3
- Bug: Path parameter consumed only by dependency treated as unconsumed (ref: #3295) HOT 1
- docs(v3): intersphinx for litestar v2 docs
- Bug: Improve warning message for ambiguous defaults HOT 1
- bug(typing): Internal type exposed on public interface
- Bug: New `create_static_files_router` automatically adds routes to schema docs HOT 4
- Enhancement: exclude default from reprs of some dataclass types HOT 1
- Enhancement(v3): Replace config objects with plugins
- Bug:AttributeError: module 'pydantic._migration' has no attribute 'JsonValue' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from litestar.