-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
dependency-function #137
dependency-function #137
Conversation
Test cases:
|
Please check sonar - also coverage is below 100%. |
Yeh this isn't ready yet. I pushed up the impl so that I could open a PR to move my checklist from the issue into here. Working on the tests now. |
Sorry. Will hold back next time. To avoid confusion, best to use a draft PR |
It is draft ;) although I marked it draft a few seconds after I created it. So Sonar should not run on drafts? |
It does. Anyhow, sorry |
No problems at all. Does it make too much noise for you if I work directly in the repo? I can be doing a lot of this in my fork if that's better? |
Not at all. I get a lot of notifications usually - work stuff. |
25ce498
to
0f47845
Compare
I've cooled on allowing validation arguments to For one thing it isn't clear what error should be returned to the client. Probably should be a 500 error by default if an explicit dependency fails validation, however that might need to be configurable, maybe It would also be possible to have both a client parameter validation failure and a dependency validation failure on the same signature model for a given request. In that case we'd probably have to return the higher status code of 400 or the status for the dependency validation failure. By excluding the validation kwargs from There is also the issue of identifying that the field that raised the |
@Goldziher I still have to do the docs, but code is ready for review. |
Ok, will review shortly. Please look in sonar and increase coverage to 100%. |
starlite/app.py
Outdated
fn=cast(AnyCallable, route_handler.fn), plugins=self.plugins | ||
fn=cast(AnyCallable, route_handler.fn), | ||
plugins=self.plugins, | ||
provided_dependencies=(route_handler.dependencies or {}).keys(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value can be placed in a variable and then used in both calls.
starlite/signature.py
Outdated
>>> get_args(Union[int, None]) | ||
(<class 'int'>, <class 'NoneType'>) | ||
""" | ||
return get_origin(annotation) in UNION_TYPES and type(None) in get_args(annotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 🚀
The one line that has no coverage in sonar is the else block for |
Yup |
df83c9b
to
dc85972
Compare
I ran into a chicken and egg scenario where I need the name of all provided dependencies to check for the error condition prior to the signature model being constructed (because I need them to check the signature model themselves). That prevents me from using @property
def dependency_name_set(self) -> Set[str]:
"""
The set of all dependency names provided in the handler's ownership layers.
Intended as a fast to compute set of the names of dependencies provided to the handler, and
available at the time that the handler's signature model is generated. Full resolution of
dependencies requires that the signature model is already generated and is performed in
``BaseRouteHandler.resolve_dependencies()``.
"""
if self.resolved_dependency_name_set is BaseRouteHandler.empty:
self.resolved_dependency_name_set = {
k
for k in itertools.chain.from_iterable(
(layer.dependencies or {}).keys() for layer in self.ownership_layers()
)
}
return cast(Set[str], self.resolved_dependency_name_set) Also added a section to the bottom of the usage docs in LMK any changes you'd like and I'll try to close this one out so I can clean up the other couple of PRs that are there. Would you prefer a squash and merge for a PR like this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff. Merge when ready .
starlite/handlers/base.py
Outdated
self.resolved_dependency_name_set = { | ||
k | ||
for k in itertools.chain.from_iterable( | ||
(layer.dependencies or {}).keys() for layer in self.ownership_layers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split this into variable rather than nest it
- defines `Dependency` in `params.py` - `Dependency` inserts `is_dependency=True` into `field.extra` - excludes explicit dependencies from parameter documentation.
…t provided. - adds `signature.detect_optional_union()` utility for determining if annotations are optional. - adds `signature.check_for_unprovided_dependency()` - adds param `provided_dependencies: AbstractSet[str]` to `model_function_signature()`
When checking that a no optional/no default dependency is provided we need to consider the handler's resolved dependencies.
Change from `provided_dependencies` to `provided_dependency_names` as a better representation of what the variable is.
03562df
to
bea863d
Compare
Kudos, SonarCloud Quality Gate passed! |
Dependency
inparams.py
Dependency
insertsis_dependency=True
intofield.extra
ImproperlyConfiguredException
when an explicit dependency has no default and is not provided to a route handler.