-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
Adds a 100 entry limit to /subjects/history.json requests. Fixes internetarchive#314.
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) |
Happy to help w/ vagrant or docker (at this point docker may be more reliable). Thanks again for contributing :) |
There was a problem hiding this 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
My vagrant seems to be crashing with "stack level too deep" errors. (It isn't actually crashing, just hanging and requiring a manual interrupt) |
and then it hangs. Any idea why? @mekarpeles |
Converted limit to int, made 100 a constant, and removed errant argument 'key'.
There was a problem hiding this 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: space after commas
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before/after >
There was a problem hiding this comment.
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'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after :
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
@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. |
re: #1238 (comment) These instructions will hopefully fix vagrant: |
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)) |
There was a problem hiding this comment.
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
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) |
@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. |
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.) |
I've changed the tag of this pull request to As a note: I posted a link to a potential solution to the problem you described above: 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': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Alright, I'm following the docker instructions right now. If all goes well, I'll be able to test this soon. |
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) |
@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 |
Won't this endpoint take precedence over this history endpoint? openlibrary/openlibrary/plugins/worksearch/subjects.py Lines 75 to 77 in 878f50e
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. |
Adds a 100 entry limit to /subjects/history.json requests.
Closes #314
Description:
In this Pull Request we have made the following changes:
Note: If anything else needs to happen for this to work, please let me know and I will fix it ASAP.