Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot define default projection and request specific field #1036

Hugoch opened this issue Jul 5, 2017 · 1 comment

Cannot define default projection and request specific field #1036

Hugoch opened this issue Jul 5, 2017 · 1 comment


Copy link

Hugoch commented Jul 5, 2017


I am trying to exclude a field from a specific endpoint when requesting /endpoint. I use

'datasource': {
            'projection': {
                'my_field_to_exclude': 0,

which works well. I can get the field on demand via /endpoint?projection={"my_field_to_exclude":1} (similar to

However I want to be able to query the endpoint for a given field with /endpoint?projection={"another_field":1}. I expect to get a response with another_field only but I only get

<link rel="collection" href="endpoint" title="mycollection"/>
<link rel="parent" href="/" title="home"/>

If I remove the datasource projection, the field appears.

Any ideas ? I am missing anything ?

Thx !

Using Eve-0.7.4.

Copy link

Amedeo91 commented Jul 5, 2017

Below the code that merge the two projection ( line 422). For me is working fine with Eve 0.7.1

If you see any use case that are not covered, please provide a PR :)

    fields = projection_
    if client_projection:
        if projection_:
            # only allow fields which are included with the standard
            # projection for the resource (avoid sniffing of private
            # fields)
            keep_fields = auto_fields(resource)
            if 0 not in client_projection.values():
                # inclusive projection - all values are 0 unless spec. or
                # auto
                fields = dict([(field, field in keep_fields) for field in
            for field, value in client_projection.items():
                field_base = field.split('.')[0]
                if field_base not in keep_fields and field_base in fields:
                    fields[field] = value
            fields = dict([(field, 1) for field, value in fields.items() if
            # there's no standard projection so we assume we are in a
            # allow_unknown = True
            fields = client_projection

Hugoch pushed a commit to Hugoch/eve that referenced this issue Jul 18, 2017
Allow mixed projections as default projection so that fields can be hidden by default and still requested in projections.
huandzh pushed a commit to huandzh/eve that referenced this issue Mar 26, 2018

- Add all fields not excluded to static projection
- Add tests and docs to these backward compatible behaviours
huandzh added a commit to huandzh/eve that referenced this issue Mar 26, 2018
Fix pyeve#1036 : allow client projection with static exclusion


- Enable client projection with static exclusive projection
- Enhance tests and docs accordingly

Projection behaviors:

- Static projection setting will allow client projection
- Static inclusive projection will block sniffing
- Static exclusive projection will allow sniffing
- Quite weird but backwards compatible...

This PR try to patch-fix the issue but not mess up with existing code. However,
current code may require some refactoring.

- NoneType projections are quite annoying and hard to maintain. Should they 
always be dictionaries and converted to None later (for flask-pymongo)?
@nicolaiarocci nicolaiarocci added this to the 0.8 milestone Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

3 participants