Issue #832 resolved

Use a get rather than a filter in the ProductManager get_by_site() method

Andre Miras
created an issue

In Satchmo 0.8.1 and also in trunk, in product/models.py we have: {{{

!python

def get_by_site(self, site=None, **kwargs):
    products = self.by_site(site=site, **kwargs)
    if len(products) == 0:
        raise Product.DoesNotExist
    else:
        return products[0]

}}}

Using Django validation would be cleaner and also better for tracking database corruptions.

Below is what the function should look like: {{{

!python

def get_by_site(self, site=None, **kwargs):
    if not site:
        site = Site.objects.get_current()
    return self.get(site = site, **kwargs)

}}}

So that it will raise MultipleObjectsReturned if we get more than one product matching and Product.DoesNotExist if no product match.

Patch attached.

Comments (3)

  1. Log in to comment