ckan/ckan — pull request #1488 by amercader (2014-02-03 11:48:17+00:00)
Title: Auth helper function `_get_object` is evil

Auth functions use helper functions to get the relevant domain object like `get_package_object`, `get_resource_object`, etc). These use `_get_object` [1], which relies on `DomainObject.get(id)` to the get the object. The problem is that if the id is `None` (eg because of a bug higher up on the logic layer), the internal implementation at the model level will eventually call `DomainObject.by_name(id)`, which will return an unexpected object, namely the most recently created instead of the expected one.

This causes significant confusion and hides bugs that are extremely difficult to debug.

The `_get_object` function should fail immediately if no id is provided.

[1] https://github.com/ckan/ckan/blob/master/ckan/logic/auth/__init__.py#L8