Skip to content

Commit

Permalink
Fix: explicit inclusive projection is ignored.
Browse files Browse the repository at this point in the history
Closes pyeve#722.
  • Loading branch information
nicolaiarocci committed Oct 2, 2015
1 parent f30ea5d commit c35ca3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion CHANGES
Expand Up @@ -6,7 +6,12 @@ Here you can see the full list of changes between each Eve release.
In Development
--------------

- Move along nothing to see here.
Version 0.6.1
~~~~~~~~~~~~~

Not released.

- Fix: explict inclusive datasource projection is ignored. Closes #722.

Stable
------
Expand Down
12 changes: 9 additions & 3 deletions eve/flaskapp.py
Expand Up @@ -498,6 +498,10 @@ def set_defaults(self):
def _set_resource_defaults(self, resource, settings):
""" Low-level method which sets default values for one resource.
.. versionchanged:: 0.6.1
Fix: inclusive projection defined for a datasource is ignored
(#722).
.. versionchanged:: 0.6
Support for 'mongo_indexes'.
Expand Down Expand Up @@ -583,8 +587,7 @@ def _set_resource_defaults(self, resource, settings):
settings['datasource'].setdefault('filter', None)
settings['datasource'].setdefault('default_sort', None)

projection = settings['datasource'].get('projection', {})
projection = projection or {}
projection = settings['datasource'].get('projection', {}).copy()

# check if any exclusion projection is defined
exclusion = any(((k, v) for k, v in projection.items() if v == 0))
Expand All @@ -608,7 +611,10 @@ def _set_resource_defaults(self, resource, settings):
self.config['VERSION_ID_SUFFIX']] = 1
projection.update(dict((field, 1) for (field) in schema))
if settings['soft_delete'] is True:
projection[self.config['DELETED']] = 1
# careful here, we want the actual settings updated, not the
# local copy
key = self.config['DELETED']
settings['datasource']['projection'][key] = 1
else:
# all fields are returned.
projection = None
Expand Down

0 comments on commit c35ca3e

Please sign in to comment.