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

Adding "paginator" in "meta" for data collections. #2

Merged
merged 11 commits into from
Apr 7, 2016

Conversation

grahamu
Copy link
Contributor

@grahamu grahamu commented Apr 6, 2016

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 25.424% when pulling 4c50787 on grahamu:add_total_count into b485afd on pinax:master.

@@ -77,16 +77,16 @@ def get_serializable_data(self, request=None):
included=self.included,
request=request,
))
return ret
return ret, dict(total_count=len(self.data))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to return the meta dictionary to get updated in self.meta. Just update here. The object state is the top-level. There are some other improvements that should be made to support that, but out of scope for this PR.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 25.46% when pulling 0e24795 on grahamu:add_total_count into b485afd on pinax:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 25.46% when pulling 0e24795 on grahamu:add_total_count into b485afd on pinax:master.

if self.meta:
self.meta.update(total_count)
else:
self.meta = total_count
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't ideal. We need to ensure self.meta is already a dict.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 25.46% when pulling 07017ed on grahamu:add_total_count into b485afd on pinax:master.

@grahamu
Copy link
Contributor Author

grahamu commented Apr 6, 2016

@brosner this fixes the "meta" dictionary existence issue. I believe meta works as desired and page[size] as well, but forthcoming tests will prove their correctness.

Removing "meta" keyword argument in methods so that
TopLevel can use it's default "meta" value instead.
@coveralls
Copy link

Coverage Status

Coverage increased (+10.1%) to 35.704% when pulling 80dc1f6 on grahamu:add_total_count into b485afd on pinax:master.

@grahamu
Copy link
Contributor Author

grahamu commented Apr 7, 2016

Yippee @brosner this is ready for review and merging

@grahamu grahamu changed the title Adding "total_count" in "meta" for data collections. Adding "paginator" in "meta" for data collections. Apr 7, 2016
@@ -43,7 +46,7 @@ def from_validation_error(cls, exc, resource_class):
errs.append(err)
return cls(errors=errs)

def __init__(self, data=None, errors=None, links=False, included=None, meta=None, linkage=False):
def __init__(self, data=None, errors=None, links=False, included=None, meta={}, linkage=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ugly no-no in Python. The dictionary (if used) is scoped globally and can have bad side-affects to meta across requests (it can share values across all requests).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple fix: check for None in __init__ and if true then set self.meta to a dictionary created in the method scope.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another fix is to leave it None and revert the behavior in serializable. Is there another reason I am not seeing for this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the reason. You need self.meta to be a dictionary in get_serializable_data. That makes sense. I say go for the first solution and in serializable don't check if self.meta is not {} but if self.meta (because {} is not {} is always True).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, I do remember reading about that bad pattern. Will fix!

@coveralls
Copy link

Coverage Status

Coverage increased (+10.1%) to 35.704% when pulling fa0d8dd on grahamu:add_total_count into b485afd on pinax:master.

@brosner brosner merged commit 6d46875 into pinax:master Apr 7, 2016
@grahamu grahamu deleted the add_total_count branch May 13, 2016 17:46
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

Successfully merging this pull request may close these issues.

3 participants