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

fields parameter never works with pagination #50

Open
nbolten opened this issue Mar 22, 2018 · 1 comment
Open

fields parameter never works with pagination #50

nbolten opened this issue Mar 22, 2018 · 1 comment

Comments

@nbolten
Copy link

nbolten commented Mar 22, 2018

Overview

Hey, thanks for the great package!

I'm trying to grab data off an esri mapserver API using the EsriDumper class, and only want to grab a few fields (hopefully speeding up download speed and decreasing file size).

What I expected to happen

When I use list(EsriDumper(url, fields=['OBJECTID'])), I get back geometries with only the OBJECTID properties.

What actually happens

I get all of the properties regardless of the fields setting.

Explanation

I noticed that even when I set fields=['OBJECTID'], I was getting back every field anyways. The cause is line 127 in dumper.py:

return data.get('error') and data['error']['message'] != "Failed to execute query."

I think the intention is to return False when the response has an error field and it doesn't have that exact message, and return True in all other cases.

What actually happens is that when there is no error, data.get('error') evaluates to None, and this is then the return value of can_handle_pagination. This gets coerced into a boolean later on in the __iter__ method:

if query_fields and not self.can_handle_pagination(query_fields):

So, the actual logic is that it will only think it can handle pagination when it receives an error other than "Failed to execute query".

Solution

I think this achieves the intended logic in can_handle_pagination:

if 'error' in data and 'message' in data['error']:
    return data['error']['message'] != "Failed to execute query."
return True
@nbolten
Copy link
Author

nbolten commented Mar 22, 2018

As a follow-up: esri mapservers seem to require OBJECTID in the outFields parameter, so this should probably be added by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant