Need help to catch "cart_id" based on session.

59 views
Skip to first unread message

Shazia Nusrat

unread,
Nov 5, 2016, 8:11:30 AM11/5/16
to django...@googlegroups.com
Hi,

I am using doorsale repo for building ecommerce site due to it's simplicity but I am stuck at the error while trying to catch cart session ID.

The repo link is:

https://github.com/mysteryjeans/doorsale


Error traceback is below:


Request Method: POST
Request URL: http://localhost:8000/sales/checkout/order/

Django Version: 1.9.11
Python Version: 2.7.12
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'doorsale',
 'doorsale.geo',
 'doorsale.pages',
 'doorsale.accounts',
 'doorsale.catalog',
 'doorsale.sales',
 'doorsale.financial',
 'doorsale.payments',
 'sorl.thumbnail',
 'pipeline')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')



Traceback:

File "/home/osboxes/Desktop/doorsaleproj/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/home/osboxes/Desktop/doorsaleproj/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/osboxes/Desktop/doorsaleproj/local/lib/python2.7/site-packages/django/utils/decorators.py" in inner
  184.                     return func(*args, **kwargs)

File "/home/osboxes/Desktop/doorsaleproj/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/home/osboxes/Desktop/doorsaleproj/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/home/osboxes/Desktop/doorsaleproj/local/lib/python2.7/site-packages/doorsale/sales/views.py" in post
  351.             cart_id = request.session['cart_id']

File "/home/osboxes/Desktop/doorsaleproj/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in __getitem__
  50.         return self._session[key]

Exception Type: KeyError

Please advice.

ludovic coues

unread,
Nov 6, 2016, 3:01:42 PM11/6/16
to django...@googlegroups.com
I would try request.session.get('cart_id', None) instead of
request.session['card_id'].

Both act the same if the key exist in the dict. When the key is
missing, the first return the second value (None in this case) while
the second raise a Key Error exception.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAD83tOzsSY%3D%2BkW6bSTWfR2ea17JgOOy%3DVNWunLR6P%3DxJDF9xRQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Melvyn Sopacua

unread,
Nov 7, 2016, 12:52:03 PM11/7/16
to django...@googlegroups.com
On Sunday 06 November 2016 21:00:44 ludovic coues wrote:

> I would try request.session.get('cart_id', None) instead of
> request.session['card_id'].

Negative.
First, this is part of the 3rd party app "doorsale". Secondly, at this
stage in the order process a cart id SHALL be present in the session and
as such we need to error out hard and not suppress.

This is a configuration issue by OP or a bug in the software, but I'm
not familiar enough with doorsale to say which. At first glance though,
the view handling it and the views preceeding this stage look solid.

--
Melvyn Sopacua
Reply all
Reply to author
Forward
0 new messages