diff --git a/ordr2/resources/base.py b/ordr2/resources/base.py index 224c6e5..b25ea29 100644 --- a/ordr2/resources/base.py +++ b/ordr2/resources/base.py @@ -30,8 +30,13 @@ class BaseResource(object): def __getitem__(self, key): - klass = self.nodes[key] - return klass(key, self) + klass = self.nodes.get(key, None) + if klass: + return klass(key, self) + try: + return super().__getitem__(key) + except AttributeError: + raise KeyError() @classmethod @@ -210,3 +215,10 @@ class PaginationResourceMixin(object): params = self.query_params(*args, **kwargs) return self.request.resource_url(self, query=params) + + def __getitem__(self, key): + model = self.request.dbsession.query(self.sql_model_class).get(key) + if not model: + raise KeyError() + return self.child_resource_class.from_sqla(model, self) +