Django-oscar: InvalidPage exceptions in CatalogueView are not properly handled

Created on 26 Jun 2020  路  3Comments  路  Source: django-oscar/django-oscar

Found a bug? Please fill out the sections below.

Issue Summary

Oscar 2.0 (sorry if already fixed..)

If the customer is on page 2 of the Shop product list, and some products are deleted such that there is now only one page, then the customer clicks 'add to cart', they are greeted with a 404 on /catalogue/?page=2

Steps to Reproduce

  1. Create 24 products, and set products to page to 20
  2. Navigate to page 2 of the shop
  3. Separate tab, delete 20 products but not the one about to be added to cart
  4. Back on the shop, click 'add to cart.'

Technical details

  • Python version: 3.8
  • Django version: 3.0
  • Oscar version: 2.0

Most helpful comment

I've retitled the issue because it's not related to adding to cart - the issue is more simply that if you pass an invalid page number to the catalogue view it will always return a 404. We're supposed to be catching the InvalidPage exception here and redirecting to the first page, but the exception is being raised too late, in get_context_data().

That is: https://latest.oscarcommerce.com/en-gb/catalogue/?page=50 should redirect to https://latest.oscarcommerce.com/en-gb/catalogue/ instead of throwing a 404.

All 3 comments

I've retitled the issue because it's not related to adding to cart - the issue is more simply that if you pass an invalid page number to the catalogue view it will always return a 404. We're supposed to be catching the InvalidPage exception here and redirecting to the first page, but the exception is being raised too late, in get_context_data().

That is: https://latest.oscarcommerce.com/en-gb/catalogue/?page=50 should redirect to https://latest.oscarcommerce.com/en-gb/catalogue/ instead of throwing a 404.

Basically, SimpleProductSearchHandler inherits MultipleObjectMixin, which catches InvalidPage and would not allow to propagate it further, but return 404 - https://github.com/django/django/blob/335c9c94acf263901fb023404408880245b0c4b4/django/views/generic/list.py#L71-L75.

Don't have better idea, other than rewrite this method ^.

Alright, got another idea to generalize pagination throughout all search handlers - https://github.com/django-oscar/django-oscar/pull/3505.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rollcat picture rollcat  路  3Comments

natea picture natea  路  7Comments

prince-tanapong picture prince-tanapong  路  6Comments

eve1234 picture eve1234  路  5Comments

jayvdb picture jayvdb  路  7Comments