Ask Your Question
0

Session key in Horizon disappear [closed]

asked 2015-03-19 10:09:15 -0600

Liced gravatar image

I have a strange behavior with sessions engine. In my form handle (in a file forms.py) I save value in request.session

class RLForm(forms.SelfHandlingForm):
    datacenter_id = forms.CharField(widget=forms.HiddenInput())
    username = forms.CharField(label=_("User Name"),
                           widget=forms.TextInput(attrs={"autofocus": "autofocus"}),
                           error_messages={
                           'required': _('This field is required.')})

    def clean(self):
        data = self.cleaned_data
        return data

    def handle(self, request, data):
        try:
            [...]
            request.session['datacenter_id'] = datacenter_id
            print(request.session.session_key)
            #datacenter_id is stored in my sessions
            return projects
        exept Exception:
            [...]

In views.py and my class, I have a get_success_url:

class RLView(forms.ModalFormView):
    form_class = RLForm
    template_name = 'project/rdc/rl.html'

    def get_success_url(self):
        print(self.request.session.keys())
        #still have my datacenter_id key in my session
        url = "/project/rdc/" + self.kwargs['datacenter_id'] + "/list-r-nets"
        return url

The destination is a other class based views

class NetView(tables.DataTableView):
table_class = NetDCTable
template_name = 'project/rdc/net.html'


def get_data(self):
    (print(self.request.session.keys())
    # datacenter_id not exist anymore !!!
    datacenter_id = self.request.session['datacenter_id']

This error is returned :

Exception Type:     KeyError
Exception Value:    'datacenter_id'

This is my settings :

SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'
SESSION_SAVE_EVERY_REQUEST = True 
SESSION_COOKIE_HTTPONLY = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_SECURE = False
SESSION_TIMEOUT = 1800

Do I miss something? Why my session key disappear? I use Horizon from github.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Liced
close date 2015-03-26 04:55:41.029581

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-03-25 12:00:52 -0600

david-lyle gravatar image

The most likely answer is that you've eclipsed the maximum size of the signed cookie. The upper limit is roughly 4K, with the token and service catalog, there is little additional room.

I suggest choosing another SESSION_ENGINE. Either backed by memcache or a DB.

For more information see https://docs.djangoproject.com/en/1.7...

edit flag offensive delete link more

Comments

Thank you.I didn't know about this limit. I did some tests and it was full as you said because I have stored a lot of things in my session.

Liced gravatar imageLiced ( 2015-03-26 04:53:16 -0600 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2015-03-19 10:09:15 -0600

Seen: 54 times

Last updated: Mar 25 '15