Skip to content

You can avoid errors that can occur as a result of updating data (in the database) that are in the self.scope that the code may depend on as these data won't be updated #1742

Discussion options

You must be logged in to vote

so the problem was in this line

user:CustomUser = self.scope['user']

which uses the scope of the instance of the consumer , this scope has just a copy of information about the user at the initiation point which means updating any info about the user after the connection wouldn't affect the user in the scope which mean saving this user object will override the new updated data which exactly what happened and could be fixed by re fetching the user object from the database so the code should be

user:CustomUser = self.scope['user']
user = CustomUser.objects.get(pk=user.pk)

and every thing is fine now .
I haven't read the source code , but I suggest that you can change the self.scope attribute…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Amohammadi2
Comment options

@ahmedyasserays
Comment options

Answer selected by carltongibson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help!
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1740 on August 23, 2021 18:25.