CH-167 Async support on Django user attach middleware#789
Open
CH-167 Async support on Django user attach middleware#789
Conversation
alxbrd
requested changes
Dec 18, 2024
| async def add_user_to_team(self, user, team_name): | ||
| # add a user from the group/team | ||
| group = Group.objects.get(name=team_name) | ||
| group = Group.objects.aget(name=team_name) |
| team = Team.objects.create( | ||
| owner=superusers[0], # one of the superusers will be the default team owner | ||
| try: | ||
| superuser = User.objects.filter(is_superuser=True).afirst() |
condar-metacell
suggested changes
Dec 19, 2024
| user.save() | ||
| user_groups += [await Group.objects.aget(name=kc_group["name"])] | ||
| await user.groups.aset(user_groups) | ||
| user.asave() |
Contributor
There was a problem hiding this comment.
Required
Another missing await here
| print(client.consume_all('my-group')) | ||
| # delete the topic | ||
| # print(client.delete_topic()) | ||
| if __name__ == "__main__": |
Contributor
There was a problem hiding this comment.
Query
This has all been indented to be inline with the async_consume body (i.e. this will be part of the async_consume method, is that intended, or should the indentation be removed to be at the module level?
| @button() | ||
| def sync_keycloak(self, request): | ||
| get_user_service().sync_kc_users_groups() | ||
| async def sync_keycloak(self, request): |
Contributor
There was a problem hiding this comment.
Query
Do these sync_keycloak methods need to be coroutines? They don't await anything, so looks like they could be normal methods, right?
Collaborator
Author
There was a problem hiding this comment.
yes probably a leftover
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes CH-167
Implemented solution
Changed the middleware to conform with this: https://docs.djangoproject.com/en/5.1/topics/http/middleware/#async-middleware
Refactored most of the code related to users sync to use asyncio apis
How to test this PR
Run any django based application using this branch (I have tested it locally on a django Ninja app)
Sanity checks:
Breaking changes (select one):
breaking-changeand the migration procedure is well described abovePossible deployment updates issues (select one):
alert:deploymentTest coverage (select one):
Documentation (select one):
Nice to have (if relevant):