-
Notifications
You must be signed in to change notification settings - Fork 5
CH-167 Async support on Django user attach middleware #789
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
base: develop
Are you sure you want to change the base?
Conversation
| 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) |
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.
await missing
| 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() |
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.
await missing
| user.save() | ||
| user_groups += [await Group.objects.aget(name=kc_group["name"])] | ||
| await user.groups.aset(user_groups) | ||
| user.asave() |
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.
Required
Another missing await here
| print(client.consume_all('my-group')) | ||
| # delete the topic | ||
| # print(client.delete_topic()) | ||
| if __name__ == "__main__": |
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.
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): |
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.
Query
Do these sync_keycloak methods need to be coroutines? They don't await anything, so looks like they could be normal methods, right?
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.
yes probably a leftover
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):