i noticed a strange behaviour when interacting with session variables in Django. In one of my app i created a middleware.py file containing a function that copy a session variable that stores an object into a local one and then i change an attribute of the object from the local var. It happens that the changes i make to the local variable are applied also to the session variable. It seems that the local var is only a reference to the session. Is this behaviour correct? Here's the code:
class CloudMiddleware(object):
user = request.session['user']
user.email = 'myemail'
When i do
user = request.session['user']
email = user.email
The value of email is equal to 'myemail'. I always thought i had to save my object back in the session if i want to store it. Could someone explain me how it really works?