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

WIP: Limit history to 100 entries #1238

Closed
wants to merge 5 commits into from

Conversation

MineRobber9000
Copy link

Adds a 100 entry limit to /subjects/history.json requests.

Closes #314

Description:

In this Pull Request we have made the following changes:

  • Manually add history to subjects.

Note: If anything else needs to happen for this to work, please let me know and I will fix it ASAP.

Adds a 100 entry limit to /subjects/history.json requests. Fixes internetarchive#314.
@MineRobber9000
Copy link
Author

Alright, I'll fix these up tommorrow (late night for me) and it should be right as rain. (currently having some issues with getting vagrant working)

@mekarpeles
Copy link
Member

Happy to help w/ vagrant or docker (at this point docker may be more reliable). Thanks again for contributing :)

Copy link
Member

@mekarpeles mekarpeles left a comment

Choose a reason for hiding this comment

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

see changes inline, the code doesn't run and has problems which need to be corrected

@MineRobber9000
Copy link
Author

My vagrant seems to be crashing with "stack level too deep" errors. (It isn't actually crashing, just hanging and requiring a manual interrupt)

@MineRobber9000
Copy link
Author

Invalid gemspec in [/usr/share/rubygems-integration/all/specifications/rbnacl-libsodium.gemspec]: stack level too deep

and then it hangs.

Any idea why? @mekarpeles

Converted limit to int, made 100 a constant, and removed errant argument 'key'.
Copy link
Member

@mekarpeles mekarpeles left a comment

Choose a reason for hiding this comment

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

Does this run?

def GET(self):
i = web.input()
try:
limit = int(i.get("limit",self.API_ROWS_LIMIT))
Copy link
Member

Choose a reason for hiding this comment

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

style: space after commas

Copy link
Author

Choose a reason for hiding this comment

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

OK!

limit = int(i.get("limit",self.API_ROWS_LIMIT))
except (ValueError, TypeError):
return {'error':'limit must be an integer'}
if limit>self.API_ROWS_LIMIT:
Copy link
Member

Choose a reason for hiding this comment

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

space before/after >

Copy link
Author

Choose a reason for hiding this comment

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

OK!

try:
limit = int(i.get("limit",self.API_ROWS_LIMIT))
except (ValueError, TypeError):
return {'error':'limit must be an integer'}
Copy link
Member

Choose a reason for hiding this comment

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

space after :

Copy link
Author

Choose a reason for hiding this comment

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

OK! Fixed the other one too!

return {'error':'limit must be an integer'}
if limit>self.API_ROWS_LIMIT:
return {'error':'limit must be less than or equal to {}'.format(self.API_ROWS_LIMIT)}
return history().get()
Copy link
Member

Choose a reason for hiding this comment

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

Does this work? I think the method is called GET not get

Copy link
Author

Choose a reason for hiding this comment

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

OK, changed to history().GET().

API_ROWS_LIMIT = 100
@jsonapi
def GET(self):
i = web.input()
Copy link
Member

Choose a reason for hiding this comment

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

this spacing is wrong, does this run?

Copy link
Author

@MineRobber9000 MineRobber9000 Oct 4, 2018

Choose a reason for hiding this comment

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

Could you please be slightly more specific? Where is the spacing wrong? How should I fix it?

@MineRobber9000
Copy link
Author

@mekarpeles see above, vagrant is not working for me. I have basically no way to test. I will fix the style comments but I can't test until I can get help and fix Vagrant.

@mekarpeles
Copy link
Member

re: #1238 (comment)

These instructions will hopefully fix vagrant:
hashicorp/vagrant#9788 (comment)

@MineRobber9000
Copy link
Author

While I try to fix vagrant, could you please take a look at the remaining problems with the code and elaborate on why it's wrong? I'm always ready to learn.

def GET(self):
i = web.input()
try:
limit = int(i.get("limit", self.API_ROWS_LIMIT))
Copy link
Member

Choose a reason for hiding this comment

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

Hi @MineRobber9000, the spacing/indentation is inconsistent on each line such that it wouldn't run.

Please paste the code here before re-submitting:
http://pep8online.com/checkresult

@mekarpeles
Copy link
Member

2018-10-06-091938_1600x900_scrot

@MineRobber9000
Copy link
Author

This PR now passes pep8 online aside from line 179. Should I worry about it? (it's 98 chars long, as opposed to the PEP8 standard 79)

@mekarpeles
Copy link
Member

@MineRobber9000 https://www.python.org/dev/peps/pep-0008/#maximum-line-length

either way, we can't merge this without it being tested and verified on a local development environment. Ideally, we'd want to include a test case that the code works correctly if over 100 records requested.

@MineRobber9000
Copy link
Author

vagrant still refuses to work for me. I'd be willing to write up a test case (though it shouldn't be hard) for "does it error correctly when you request too many records" but I cannot test this codebase.

(as an aside, maybe I can get Docker to work.)

@mekarpeles mekarpeles changed the title Limit history to 100 entries WIP: Limit history to 100 entries Oct 6, 2018
@mekarpeles
Copy link
Member

I've changed the tag of this pull request to WIP (work in progress) as it's not ready to be considered for merge. If you're having trouble getting vagrant or docker up-and-running, can you please upon another issue describing what you're experiencing so we can help you work through it?

As a note: I posted a link to a potential solution to the problem you described above:
#1238 (comment). Docker is our preferred method of setup.

p.s. It would be really helpful if you could spend a bit more independently researching / testing before asking for a review because we have many issues and pull requests requiring attention and several of the issues (e.g. line indentation, no such function existing) could have been discovered by linting + testing (even if vagrant wasn't working) without requiring our assistance. Happy to help if no other resources are available, but if we have to act as a python interpreter for your PR, it's actually less work for us to solve the issue ourselves :). Thanks for understanding and for your continued effort!

@@ -176,7 +176,9 @@ def GET(self):
except (ValueError, TypeError):
return {'error': 'limit must be an integer'}
if limit > self.API_ROWS_LIMIT:
return {'error': 'limit must be less than or equal to {}'.format(self.API_ROWS_LIMIT)}
return {'error':
Copy link
Member

Choose a reason for hiding this comment

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

👍

@MineRobber9000
Copy link
Author

Alright, I'm following the docker instructions right now. If all goes well, I'll be able to test this soon.

@MineRobber9000
Copy link
Author

MineRobber9000 commented Oct 6, 2018

Alright, I got the docker images built. How do I go about testing? (do I just try to cause the error to occur?)

(I couldn't find an answer elsewhere)

@mekarpeles
Copy link
Member

@MineRobber9000 if you visit the endpoint in your browser (localhost:8080 I think it is, once docker is running) you should be able to cause the error by using limit=101

@hornc
Copy link
Collaborator

hornc commented Oct 9, 2018

Won't this endpoint take precedence over this history endpoint?

class subjects_json(delegate.page):
path = '(/subjects/[^/]+)'
encoding = "json"

Sorry to be late to the conversation, but now that I've looked into it, /subjects/history.json looks to me like just an example of a particular book subject, rather than a edit history.

@mekarpeles
Copy link
Member

I think @hornc is right, we should move this issue into @infogami. Thanks everyone for your input!

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.

Infogami API Endpoints Not Enforcing Sensible Result Limits
4 participants