1. Jesper Noehr
  2. django-piston
  3. Issues
Issue #152 new

Fix QuerySet filtering on BaseHandler.read()

created an issue

By default, the {{{BaseHandler.read}}} method takes a {{{**kwargs}}} argument that is handled to the {{{QuerySet.filter}}} method so that one can get filtered results from a Handler. However, this is ignored when we looking for a single object (i.e., looking for a particular pk) instead of a collection, which is inconsistent.

I made some changes (with tests) in https://bitbucket.org/k0001/django-piston/changeset/2ea798ed0f42 so that:

  • A single object lookup happens on the already-filtered {{{ QuerySet}}}, making it consistent with a collection lookup.
  • Getting a {{{MultipleObjectsReturned}}} exception when looking for a single object doesn't return {{{rc.BAD_REQUEST}}} anymore. That's an unexpected model design error the programer is responsible for; a 500 is more apropiate.

Additionaly, I've added the follwing enhacement:

  • Single object lookups can be done using either the name of the primary key field, or {{{pk}}} (i.e., provided {{{id}}} is the name of the primary key: {{{kwargs={'pk': '1'}}}} and {{{kwargs={'id': '1'}}}} give the same results).

Comments (0)

  1. Log in to comment