By default, as it is in Giovanni’s comment, user login and session information is stored in the database by Django’s Session middleware. As they are the same database, and without any additional config, and an unexpected use (unlike, for example, the same user being logged in from different browsers on the same system - a much more common case), the middleware is nesting.
Looking quickly at Django’s code, it seems that the part that invalidates the Session of another system in the same bank will be this thingy here:
except Exception as e:
# ValueError, SuspiciousOperation, unpickling exceptions. If any of
# these happen, just return an empty dictionary (an empty session).
if isinstance(e, SuspiciousOperation):
logger = logging.getLogger('django.security.%s' % e.__class__.__name__)
logger.warning(str(e))
return {}
(in django.contrib.session.backends.base.py
~line 110) -
If you look at the logs of the systems you should see the Warning logged in above. )
Apparently this is not an expected scenario even in Django - Session’s middleware does not provide a way to change the table name used by the bank, for example. If on one of the systems you can switch from bank sessions to another type - with the configuration of the Session engine, should solve your problem.
If you want to keep Session on the bench for both of us, the remedy will be to create your own Session.engine class, inheriting precisely from django.contrib.sessions.backends.db.SessionStore
- and in your inherited class, you modify the method get_model_class
for a another class you should inherit from from django.contrib.sessions.models.Session
- and in your Session
inherited, you change the information of Meta.db_table. Aí você aponta para o módulo, dentro do seu projeto, onde criou a nova classe
Sessionstorena configuração
SESSION_ENGINE` of your Settings.
In short, within your project, a file that will look something like:
from django.contrib.sessions.backends.db import SessionStore as BaseSessionStore
from django.contrib.sessions.models import Session as BaseSession
class Session(BaseSession):
class Meta(BaseSession.Meta):
db_table = "sistema_y_django_session"
class SessionStore(BaseSessionStore):
@classmethod
def get_model_class(cls):
return Session
And point that file at SESSION_ENGINE
What middleware applications are using?
– Woss
@Andersoncarloswoss edited the question and added the middleware, the two projects are using the same
– Leila
The Django persist the logged user information in the database (table
django_session
) and whether how the applications are sharing is well capable of one being "sabotaging" the other. Take a test with the login in each version and check what is registered in the table.– Giovanni Nunes