Skip to content
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

Add an ability to replace dependencies for an arbitrary endpoint #54

Open
zmievsa opened this issue Sep 23, 2023 · 1 comment
Open

Add an ability to replace dependencies for an arbitrary endpoint #54

zmievsa opened this issue Sep 23, 2023 · 1 comment
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@zmievsa
Copy link
Owner

zmievsa commented Sep 23, 2023

See #11 for more details.

Replacing individual params (query, header, cookie)

endpoint("/v1/users/{user_id}", ["GET"]).dependency("param_name").was(Query()) # 1
endpoint("/v1/users/{user_id}", ["GET"]).dependency("param_name").was(Depends(get_param_dependency)) # 2

@endpoint("/v1/users/{user_id}", ["GET"]).dependency("param_name").was # 3
def apply_some_changes_to_dependency():
    def any_name_here(anything_here: str = Query()):
        # Do any actions with the dependency here
        return anything_here


    return Depends(any_name_here)
  1. (accepts an instance of Header/Query/Cookie) Allows you to change the type (header/query/cookie) or config of any dependency. Body should not be supported!
  2. (accepts an instance of Depends) Allows you to change some dependency entirely to another function. It's useful when you want to change dependency's logic without affecting your route. However, sometimes type hints of the dependency cause circular imports from the business logic which is why we have Path 3.
  3. (accepts a callable that returns a callable) Is same as 2 except that it allows you to import things after the migration has been defined so it solves the problem of circular imports. It's needed extremely rarely.

You can use APIRoute.dependency_overrides_provider for 3. Not sure if you should though...

Rejected solutions

@dependency("api.v1.users:some_dependency").was
def anything_here():
   ...

It is really implicit and prone to errors. It doesn't really give us anything in terms of functionality over the solutions above so I decided that it was a bad idea to include it.

Changing logic for handling params or removing the param completely

At this point it makes a lot more sense to just replace the route function.

@zmievsa zmievsa added the enhancement New feature or request label Sep 23, 2023
@zmievsa zmievsa added this to the Request Migrations milestone Sep 23, 2023
@zmievsa
Copy link
Owner Author

zmievsa commented Aug 17, 2024

It is probably going to make Cadwyn too complex. However, we do need significant improvements in terms of documenting + testing + fixing our current dependencies approach

@zmievsa zmievsa added the wontfix This will not be worked on label Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant